c - No response from UART -
i'm able receive next code, unfortunately, nil sent back. doing wrong?
#include <pic18f25k80.h> #include "config.h" #include <usart.h> int = 0; unsigned char messagebuffer[200]; void main() { oscconbits.ircf = 0b110; // 8mhz trisb6 = 0; // tx set output trisb7 = 0; // rx set output // clear tx interrupt // set rx interrupt // 8-bit asynch. mode // brgh = 1 = high baud mode // 51 = ((8mhz/baud)/16)-1 baud = 9600 open2usart(usart_tx_int_off & usart_rx_int_on & usart_asynch_mode & usart_eight_bit & usart_brgh_high, 51 ); rc2if = 0; // reset rx2 flag rc2ip = 0; // not high priority rc2ie = 1; // eneble rx2 interrupt intconbits.peie = 1; // enable peripheral interrupts intconbits.gie = 1; // enable interrupts rcsta2bits.spen = 1; // enable usart while(1){ } } void interrupt isr () { if(pir3bits.rc2if == 1) { if(i<200) { // buffer size messagebuffer[i] = read2usart(); // read byte rx reg if (messagebuffer[i] == 0x0d) { // check homecoming key puts2usart(messagebuffer); for(;i>0;i--) messagebuffer[i] = 0x00; // clear array i=0; return; } i++; rc2if = 0; // clear rx flag } else { puts2usart(messagebuffer); for(;i>0;i--) messagebuffer[i] = 0x00; // clear array = 0; return; } } }
i'm transmitting 0x41 hex code, checked scope , see is beingness received. , according code have, echo of received info should sent back. when check tx pin, nil happening.
add usart_cont_rx open2usart enable continuous receive.
also, it's thought minimum necessary in interrupt service routine. consider like:
void interrupt isr () { char data; if(pir3bits.rc2if == 1) { info = read2usart(); // read byte rx reg (clears rc2if) if(i<200) { // buffer size messagebuffer[i] = data; // read byte rx reg i++; } else{ // flag buffer total error } } }
and doing rest of doing in while(1) loop.
c microcontroller pic uart
No comments:
Post a Comment