Do you have RS232 level shifting hardware?
DLC
englsprogeny wrote:
> Hi everyone.
>
> I am trying to get an ATMEGA8 to talk to a terminal app on my PC by
> RS232. I have used the compiler [WinAVR] and programmer [PONY ISP]
> to compile and run other programs so I know that these parts of the
> issue are OK.
>
> Here is the source....
>
>
>
> Any ideas?
>
>
> I have an 8Mhz oscillator
>
> Note: if anyone has simpler source with makefile please send it to
> me. Thanks
>
>
>
> * >simcom -38400 /dev/ttyS0 */
>
> #include <avr/io.h>
> #include <avr/signal.h>
> #include <avr/interrupt.h>
>
> static void putchar(unsigned char ch){
> while ((inp(UCSRA) & 0x20) == 0) {};
> outp(ch, UDR);
> while ((inp(UCSRA) & 0x20) == 0) {};
> }
>
>
> SIGNAL(SIG_ADC){
> static int ctr1;
> static char lbyte,hbyte;
> ctr1++;
> lbyte = inp(ADCL);
> hbyte = inp(ADCH);
>
> if (ctr1>=1000){
> putchar(lbyte);
> //putchar('A');
> ctr1 = 0;
> }
>
>
> outp(BV(ADEN)|BV(ADSC)|BV(ADIE)|BV(ADPS2)|BV(ADPS1)|BV
> (ADPS0),ADCSR);
> // Internal Vref, right adjust
> // Enable ADC interrupts, Clock/128
> }
>
>
> SIGNAL(SIG_UART_RECV){
> char ch = inp(UDR);
> putchar(ch);
> }
>
> SIGNAL(SIG_OVERFLOW0){
> static int ctr;
> ctr++;
>
> if (ctr>=10){
> //putchar('O');
> ctr = 0;
> }
>
> }
>
> int main(){
> int i,j;
>
> outp(BV(TOIE0),TIMSK); // Enable TCNT0
> outp(0x00,TCNT0); // Reset TCNT00, CLK/1024
> outp(BV(CS02)|BV(CS00), TCCR0);
>
> outp(0x00, UCSRA); // USART:
> outp(0x98, UCSRB); // USART: RxIntEnable|RxEnable|TxEnable
> outp(0x86, UCSRC); // USART: 8bit, no parity
> outp(0x00, UBRRH); // USART: 38400 @ 8MHz
> outp(12, UBRRL); // USART: 38400 @ 8MHz
>
> /*outp(0xce, ADMUX); // Internal Vref, right adjust, read 1.22V
> (Vbg)*/
> outp(BV(REFS1)|BV(REFS0)|BV(MUX1),ADMUX); //ADC2
>
> // Enable ADC interrupts, Clock/128
> outp(BV(ADEN)|BV(ADSC)|BV(ADIE)|BV(ADPS2)|BV(ADPS1)|BV
> (ADPS0),ADCSR);
>
> putchar('M');
>
> sei();
>
> while (1) {
>
> /* putchar('L'); */
> for(i = 0;i<10000;i++){
> j = 1+1;
> }
>
> }
> }
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
--
---------------------------------------
Dennis Clark TTT Enterprises
---------------------------------------Message
Re: [AVR-Chat] MEGA8 RS232
2007-03-09 by Dennis Clark
Attachments
- No local attachments were found for this message.