Hi I was unable to get data properly through High Speed uart's. as per my program i was able to get only 64 bytes properly after that not getting. Here i am posting the program Please take a look and give me the Directions Thank You
int main(void) { unsigned char i; init_HSUART1(); while(1) { //HSUART1_senddata(HSUART1_receivedata()); HSUART1_senddata('1'); HSUART1_senddata('2'); HSUART1_senddata('3'); HSUART1_senddata('4'); HSUART1_senddata('5'); } } void init_HSUART1 (void) { HSU1_RATE =192;// baud rate 115200 for 13MHz CLK HSU1_CTRL= 0x00001C00; } /**************************************************************************************** ** DESCRIPTION : This function waits until its receives a character from the terminal. ** ** RETURN : Character received from the terminal *****************************************************************************************/ unsigned char HSUART1_receivedata(void) { unsigned char gch; while((HSU1_RX&0x0100)==0x0100); //cheak for data availability gch = HSU1_RX; // Storing data into temp variable 'gch' return(gch); // Return the data } /************************************************************************************ ** DESCRIPTION : This function transmits the given character to the terminal. * ** * ** RETURN : None * ************************************************************************************/ void HSUART1_senddata(unsigned char pch) { HSU1_TX=pch; // while((HSU1_IIR&0x01)==0x01); // Transmiting data into buffer /* if((HSU1_LEVEL&0xFF00)==0x0400) { while((HSU1_LEVEL&0xFF00)==0x0000); } else{} */ return ; /*if((HSU1_IIR&0x01)==0x01) { HSU1_IIR|=0x01; // Clear or ACK the interrupt HSU1_TX=pch; // Transmiting data into buffer } return; */ }
When you read to check the status of the receive FIFO, you are removing a (potentially) pending character from the FIFO.
So your receive code would be better as something like:
unsigned char HSUART1_receivedata(void) { unsigned int gch; // Wait for character to become available do { gch = HSU1_RX; } while((gch&0x0100)==0x0100); // Return the character now read, with FIFO status removed return((unsigned char)(gch&0xFF)); }
(I'll leave you to tidy it up!)
Thank You for reply. I just received on other logic. But i'll try this one also.
Thanks
Hi Thanks for your help regarding UART. Now i have one more problem. I'm trying to receive the data using trigger levels. But from the first byte interrupt coming. As per the datasheet the interrupt has to come after reaching the trigger level only. But i'm getting interrupt for single character.
here i am attaching the configuration. Please help me.
U6LCR=0x83;//DLAB enable,odd parity,disble break transmission,1 stop bit,8 bit character length U6CLK =0x00000101; //x=1,y=1..115200 U6DLL=0x07; //115200 baud rate U6DLM=0x00; U6LCR=0x03; //DLAB Disable,odd parity,disble break transmission,1 stop bit,8 bit character length U6IER |=0x03; // Enable Uart6 Rx & Tx interrupt U6FCR =0x1F;
Thanks eswar
You don't mention the frequency at which you are sending characters to the UART.
It would be typical for the UART with FIFOs enabled to generate an interrupt when:
1 - The FIFO trigger point has been reached 2 - If something is in the FIFO, but no further character has been received for 'a period'
So, if you only send one character (or send multiple characters with a relatively large delay between them), you should expect to see an interrupt for each character.
i am sending with 115200 baud rate. char time outCTI interrupt is coming. my requirement is i have to receive 4 bytes as burst and reply with some bytes and again read 8 bytes to start my process. because of the UART6 which i am using don't support DMA to read and send burst i have to enable FIFO for trigger levels. why interrupt coming for each character. How to configure for trigger level.
If you're getting a timeout interrupt, then the characters are coming in with a (relatively large) delay somewhere.
Getting an interrupt like this is useful and you should probably cope with it anyway. Consider what would happen if one of your 4 bytes 'goes missing' (which is not unheard of when using serial communication). You might only receive 3 of your 4 bytes and you will potentially be waiting forever for the 4th byte. So you should implement some sort of timeout check anyway.
It looks like you've got a relatively small amount of communication, so it may be simpler to buffer up characters into a local store as you receive them. Then, it won't matter whether you receive a single interrupt when the FIFO trigger is reached or when you have accumulated your data from a series of interrupts.
View all questions in Keil forum