avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Software UART receiver first byte as NULL / empty


From: harshit suri
Subject: RE: [avr-gcc-list] Software UART receiver first byte as NULL / empty
Date: Fri, 12 Mar 2004 23:21:20 -0800 (PST)

I got the bug. After reading the manual again. I
realised that my UartswInitRoutine wasn't reseting the
EIFR flag for the external interrupt
so i has to add this to solve the problem

EIFR = BV(UartswRxPin);  

Even though the manual says that u have to reset the
flag, I dont understand what makes the external
interrupt require this. No other interrupt require the
reseting of the flag on initialization(at least the
ones that i used in the timers).
This one was a subtle one(at least for me)
thanks to all for their advice and help. I am posting
the corrected code for anyone who may bump into
something similar in the future. 
Regards



void uartswInitRx(void)
{
        // initialize the buffers
        uartswInitBuffers();
        // initialize the ports
        cbi(DDRD, UartswRxPin); //set as input RX recieve Pin
of software UART uses the ecternal interrupt 0 for
start bit interrupt
        // initialize baud rate
        uartswSetBaudRate(9600);
        // set timer prescaler
        timer1SetPrescaler(TIMER_CLK_DIV1);
        // attach RxStart service routine to ICP :this is
hard coded as SIG_INTERRUPT0 ISR for now which simply
calls uartswRxBitService

        //      timerAttach(TIMER1INPUTCAPTURE_INT,
uartswRxBitService);
        // attach RxBit service routine to OC1B
        timerAttach(TIMER1OUTCOMPAREB_INT,
uartswRxBitService);
        //harshit : the following line of code enables the
input capture interrupt IC
        //note the OC1B itnerrupt is used to generate the
recieve timings and is enabled in the Receieve bit ISR
.The timerattach above simply links the OC1B ISR to
the usartsxRxBitService Routine
        EIMSK = 0x00;
        // trigger on rising edge
        EICRA = 0x00; //initialize for masking 
        //for trigger on rising edge the sense control bits
have to be = (11)2
        EICRA |= BV(UartswRxPin * 2);       //enable
interrupt linked to UartswRx Pin to trigger on the
rising edges.
        EICRA |= BV((UartswRxPin * 2) + 1);  //enable
interrupt linked to UartswRx Pin to trigger on the
rising edges
        EIFR = BV(UartswRxPin);  
        //enable the external interrupt
        EIMSK = BV(UartswRxPin);        
        // turn on interrupts
        sei();
}

--- Douglas Dotson <address@hidden> wrote:
> I missed the first part of this thread so sorry if
> this is redundant. I remember when using an
> Intel 8251 USART one had to do a couple of reads
> during initialization to clear out any bogus
> characters. This was due to the double buffering
> scheme in the chip itself. The reads cleared out
> any junk there from power up.
> 
> Doug
> 
> --- harshit suri <address@hidden> wrote:
> > Thanks for ure reply. I am posting the basic stamp
> > code as u asked. I have also tried doing 
> > serout 6,16468,["HowdyAtmega01234"] .It yield the
> > same
> > problem. Any help will be aprreciated
> > 
> > 
> > '{$STAMP BS2}
> > 
> > 'this code implements the commn protocol
> > 'it tries to communicate with the atmega128
> > 
> > rx con 5 'receive from atmega
> > tx con 6  'transmit to atmega
> > input 5
> > output 6
> > looper:
> > 'make my tx high to indicate to atmega128 that i
> am
> > ready to send
> > high 6
> > 
> > 
> > 'wait for atmega128 to acknowledge
> > wait_for_ack:
> > if IN5 = 1 then sendbyte 'that means atmega shall
> > give
> > the stamp a chance to communicate.This DOES NOT
> mean
> > that he has set up his uart
> > goto wait_for_ack
> > 
> > sendbyte:
> > low 6 'lower the tx line telling mega that ill
> send
> > data whenever atmega is ready
> > 
> > wait_till_atmega_has_setup_UART:
> > if IN5=0 then senddata 'wait for atmega128 to
> lower
> > its txline that means that atmega has set up his
> > uart
> > and is ready to receive
> > goto wait_till_atmega_has_setup_UART
> > 
> > senddata:
> > serout 6,16468,["H"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["o"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["w"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["d"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["y"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["A"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["t"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["m"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["e"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["g"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["a"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["0"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["1"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["2"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["3"] 'send data at 9600baud 8N1
> > inverted LSB first
> > serout 6,16468,["4"] 'send data at 9600baud 8N1
> > inverted LSB first
> > 'right now atmega is printing out what it recvd to
> > the
> > debug terminal
> > goto looper 'do whole step again...this makes sure
> > experiment is repeatable and error free
> > 
> > 
> > 
> > --- "D. Daniel McGlothin" <address@hidden>
> > wrote:
> > > I'm curious about the exact Basic Stamp commands
> > > that you are using to
> > > send the data to the AVR.  Could you post the
> > > relevant portion of the
> > > Stamp's program?
> > > 
> > > Daniel
> > > 
> > > > -----Original Message-----
> > > > From: address@hidden
> > > > [mailto:address@hidden
> Behalf
> > Of
> > > harshit suri
> > > > Sent: Friday, March 12, 2004 12:55 PM
> > > > To: address@hidden
> > > > Subject: RE: [avr-gcc-list] Software UART
> > receiver
> > > first
> > > > byte as NULL /
> > > > empty
> > > >
> > > >
> > > > i was thinking the same ..that the handshaking
> > > might
> > > > be triggering a start bit ISR. *But* the
> > waveform
> > > at
> > > > the RX pin of the atmega128 is absolutely
> clear
> > no
> > > > spurious noise bits.The devices dont need
> level
> > > > converters both are 0-5V . And as i said if i
> > > remove
> > > > the handshaking and all i do is listen in the
> > mega
> > > and
> > > > tx from stamp continousule. then all is fine.
> > > Thanks
> > > > for ure reply.
> > > > Regards
> > > >
> > > > --- Rune Christensen
> > > <address@hidden>
> > > > wrote:
> > > > > Hello
> > > > >
> > > > > If the handshaking uses the rx and tx
> signals
> > > maybe
> > > > > it will trigger a false
> > > > > start bit.
> > > > > Normally handshaking uses other dedicated
> pins
> > > for
> > > > > that purpose.
> > > > >
> > > > > If you don't have enough pins then maybe
> > > consider
> > > > > software handshaking
> > > > > instead of hardware handshaking.
> > > > >
> > > > > Have you voltage level conversion between
> the
> > > two
> > > > > devices?
> > > > >
> > > > > Cheers
> > > > > Rune Christensen
> > > > >
> > > > > -----Original Message-----
> > > > > From: address@hidden
> > > > > [mailto:address@hidden
> > Behalf
> > > Of
> > > > > harshit suri
> > > > > Sent: Friday, March 12, 2004 10:21 AM
> > > > > To: address@hidden
> > > > > Subject: [avr-gcc-list] Software UART
> receiver
> > > first
> > > > > byte as NULL /
> > > > > empty
> > > > >
> > > > >
> > > > > I am using the Software Uart Code from
> > > > >
> > http://hubbard.engr.scu.edu/embedded/avr/avrlib/
> > > . I
> > > > > am using a basic stamp to send data to the
> > > > > atmega128.
> > > > > I uses a handshaking protocol to
> communicate.
> > > The
> > > > > stamp sends 16 bytes
> > > > > "HowdyAtmega01234"
> > > > > and the software uart(its interrupt based)
> > > listens
> > > > > for
> > > > > 16 bytes at once.
> > > > >
> > > > > The problem is that the atmega reads a NULL
> > byte
> > > > > first
> > > > > before reading the 'H' in Howdy . So when i
> > > print it
> > > > > out it prints:
> > > > >
> > > > > Byte[0] =
> > > > > Byte[1] =H
> > > > > Byte[2] = o
> > > > > Byte[3] = w
> > > > > Byte[4] = d
> > > > > Byte[5] = y
> > > > > Byte[6] = A
> > > > > Byte[7] = t
> > > > > Byte[8] = m
> > > > > Byte[9] = e
> > > > > Byte[10] = g
> > > > > Byte[11] = a
> > > > > Byte[12] = 0
> > > > > Byte[13] = 1
> > > > > Byte[14] = 2
> > > > > Byte[15] = 3
> > 
> === message truncated ===
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]