Saturday, 15 August 2015

c - Interrupt to Send and Receive String -



c - Interrupt to Send and Receive String -

can show illustration code or link help me solve problem. want receive , transmit string using terminal.

till now, got -->

void usart_init(void) { ubrrh = 0x00; ubrrl = 95; ucsrb = (1 << rxen) | (1 << txen) | **(1<<rxcie)**; ucsrc = (1<<ursel)|(1<<usbs)|(3<<ucsz0)|(1 << ucsz1); } isr (usart_rxc_vect) { portd= 0b00000100; //enable rts char receivedbyte ; receivedbyte = udr ; // fetch received byte value variable " bytereceived " udr = receivedbyte ; // echo received byte computer portd= 0b00000000; //disable rts } int main (void) { usart_init(); while(1) { sei(); } homecoming 0; }

but can transmit , receive a character. how modified code enable send , transmit a string.

thank help :)

this question related to other question. see, want go interrupt driven approach now.

your should familiarize how strings handled in c in general. in essence, write received character array (which receive buffer). instead of

receivedbyte = udr

you write this

_receivebuffer[i++] = udr

where _receivebuffer global array this

char _receivebuffer[100];

for example. have check buffer overflow , utilize pointer arithmetic handle stuff, should started.

some comments on code:

isr (usart_rxc_vect) { portd= 0b00000100; //enable rts char receivedbyte ; receivedbyte = udr ; // fetch received byte value variable " bytereceived " udr = receivedbyte ; // echo received byte computer portd= 0b00000000; //disable rts }

you shouldn't echo info within isr or time consuming, risk blocking isr. while specific code work, not waiting info transmitted, isn't practice. , sure utilize hardware handshaking? in previous post doesn't it, can remove 2 lines potential rts signal toggled.

while(1) { sei(); }

continuously calling sei() makes no sense. sei() enables global interrupt flag, sufficient once.

i suggest read c , avr tutorials, since lack basic understanding.

c string avr uart avr-studio5

No comments:

Post a Comment