I'm using SB70LC development board and I need to receive bytes of data through UART0 or UART1.
Can you tell me how to receive UART data in interrupt mode?
How to enable UART interrupt and how to write UART ISR?
how to receive UART data
Re: how to receive UART data
#include <serial.h>
int serial_fd=SimpleOpenSerial(portnumber, baudrate);
//If you need to set other than 8 bits no parity use the OpenSerial function instead
Then using that serial_fd..... you can use all the functions defined below....
Just one note, the one thing every one gets wrong....
read returns at least one, and whatever is in the buffer up to the maximum specified...
So if you want to read 10 bytes....
read(fd,buf,10);
Will probably ONLY read one byte.... the processor is fast so when serial charactors come it in will likely wait for a char and as soon as it has one it will return...
to read at least n bytes you will need somehtign that looks like:
int n=0;
while(n<Num_To_Read)
{
int rv=read(fd,buffer+n,(Num_to_Read-n));
if(rv>0)
n+=rv;
else break; //Values < 0 are errors...
}
/**********************************************************************/
/* read data from a file descriptor */
/* returns the number of charactors read.on success. */
/* returns a number <0 on failure. */
/**********************************************************************/
int read( int fd, char *buf, int nbytes );
/**********************************************************************/
/* write data to a file descriptor */
/* returns the number of charactors written on success. */
/* returns a number <0 on failure. */
/* */
/* Note: It is possible for this call to return a number less */
/* than the requested number of bytes. */
/**********************************************************************/
int write( int fd, const char *buf, int nbytes );
/*Write a string to the file descriptor*/
int writestring( int fd, const char *str );
/* Write to a FD blocking until the write is complete */
int writeall( int fd, const char *buf, int nbytes );
/**********************************************************************/
/* read data from a file descriptor a timeout limit. */
/* returns the number of charactors read.on success. */
/* returns a number <0 on failure. */
/* returns 0 on Timeout */
/**********************************************************************/
int ReadWithTimeout( int fd, char *buf, int nbytes, unsigned long timeout );
/**********************************************************************
* Check to see if data is availible for read
* returns 1 if data is availible.
* returns 0 if no data is availible.
**********************************************************************/
int dataavail( int fd );
int serial_fd=SimpleOpenSerial(portnumber, baudrate);
//If you need to set other than 8 bits no parity use the OpenSerial function instead
Then using that serial_fd..... you can use all the functions defined below....
Just one note, the one thing every one gets wrong....
read returns at least one, and whatever is in the buffer up to the maximum specified...
So if you want to read 10 bytes....
read(fd,buf,10);
Will probably ONLY read one byte.... the processor is fast so when serial charactors come it in will likely wait for a char and as soon as it has one it will return...
to read at least n bytes you will need somehtign that looks like:
int n=0;
while(n<Num_To_Read)
{
int rv=read(fd,buffer+n,(Num_to_Read-n));
if(rv>0)
n+=rv;
else break; //Values < 0 are errors...
}
/**********************************************************************/
/* read data from a file descriptor */
/* returns the number of charactors read.on success. */
/* returns a number <0 on failure. */
/**********************************************************************/
int read( int fd, char *buf, int nbytes );
/**********************************************************************/
/* write data to a file descriptor */
/* returns the number of charactors written on success. */
/* returns a number <0 on failure. */
/* */
/* Note: It is possible for this call to return a number less */
/* than the requested number of bytes. */
/**********************************************************************/
int write( int fd, const char *buf, int nbytes );
/*Write a string to the file descriptor*/
int writestring( int fd, const char *str );
/* Write to a FD blocking until the write is complete */
int writeall( int fd, const char *buf, int nbytes );
/**********************************************************************/
/* read data from a file descriptor a timeout limit. */
/* returns the number of charactors read.on success. */
/* returns a number <0 on failure. */
/* returns 0 on Timeout */
/**********************************************************************/
int ReadWithTimeout( int fd, char *buf, int nbytes, unsigned long timeout );
/**********************************************************************
* Check to see if data is availible for read
* returns 1 if data is availible.
* returns 0 if no data is availible.
**********************************************************************/
int dataavail( int fd );
Re: how to receive UART data
Thank you!
Actually, there is a protocol between development board and our product via UART, and I think it's a good way to receive data by myself, byte to byte, and I'll know wheather there is 'package' or not, I think the interrupt will be a good way.
It seems the function SimpleOpenSerial() will enable the UART interrupt, is it correct?
if so, how to write ISR?
Actually, there is a protocol between development board and our product via UART, and I think it's a good way to receive data by myself, byte to byte, and I'll know wheather there is 'package' or not, I think the interrupt will be a good way.
It seems the function SimpleOpenSerial() will enable the UART interrupt, is it correct?
if so, how to write ISR?
Re: how to receive UART data
The ISR is already written...
It loads received chars into the buffer, just use the read function...
you won't miss any and you will see chars one at a time...
It loads received chars into the buffer, just use the read function...
you won't miss any and you will see chars one at a time...