(I've an atmega32) abcminiuser - Apr 05, 2007 - 12:33 PM Post subject: Please use the [code ] [ /code] tags (without the spaces) when posting code - it keeps the formatting and makes it easier to read. I've fixed your above post, but the indentation was eaten by the board. You don't seem to have set up the ADC in your code. You need to do that before the ADCH/ADCL register values become valid. Also, "sensor" isn't defined in your code. Where is it defined and what is it defined as? The shifting and of the two ADC registers creates a 16-bit value (of which only 10 bits are used), which is placed in your "Sensor" variable. However, the UDR register is only 8-bit, so you'll be loosing bits when you send them. You seem to have some weird shifting going on: Code: UDR = ((sensor<< 6)>>4)| 0x01; //send value to software Equates to: Code: UDR = ((sensor << 2)| 0x01); //send value to software Which means you're shifting the 10 bits to the left twice, then ORing with 0x01. That will cause bit 0 to always be one, and bit 1 to always be read as 0. Is this what you want? Also, since UDR is only 8 bit as mentioned, that value will be cast down and the upper 8 bits thrown away. So what you're actually sending is the lower 6 bits of the ADC register pair shifted left twice, and the LSB set. - Dean Twisted Evil lfmorrison - Apr 05, 2007 - 01:07 PM
(I've an atmega32) abcminiuser - Apr 05, 2007 - 12:33 PM Post subject: Please use the [code ] [ /code] tags (without the spaces) when posting code - it keeps the formatting and makes it easier to read. I've fixed your above post, but the indentation was eaten by the board. You don't seem to have set up the ADC in your code. You need to do that before the ADCH/ADCL register values become valid. Also, "sensor" isn't defined in your code. Where is it defined and what is it defined as? The shifting and of the two ADC registers creates a 16-bit value (of which only 10 bits are used), which is placed in your "Sensor" variable. However, the UDR register is only 8-bit, so you'll be loosing bits when you send them. You seem to have some weird shifting going on: Code: UDR = ((sensor<< 6)>>4)| 0x01; //send value to software Equates to: Code: UDR = ((sensor << 2)| 0x01); //send value to software Which means you're shifting the 10 bits to the left twice, then ORing with 0x01. That will cause bit 0 to always be one, and bit 1 to always be read as 0. Is this what you want? Also, since UDR is only 8 bit as mentioned, that value will be cast down and the upper 8 bits thrown away. So what you're actually sending is the lower 6 bits of the ADC register pair shifted left twice, and the LSB set. - Dean Twisted Evil lfmorrison - Apr 05, 2007 - 01:07 PM
USART.docx