-
Notifications
You must be signed in to change notification settings - Fork 6
UART API
Ankur Yadav edited this page Aug 27, 2015
·
7 revisions
#UART API
This page contains native API functions for accessing UART of beaglebone black. Code of this API can be found in uart.c. Sample JNI wrapper functions can be found here. Sample application for UART can be found here
###UART API functions description
- int uartOpen(const uint8_t device, const uint32_t bdrate) : This takes device number and baud rate as input and opens uart deivce with specified baud rate and returns the file descriptor.
Returns : If successful then UART file descriptor is returned and if it fails then -1 is returned.
Note : There are currently only these baud rates possible.
switch(baudrate)
{
case 0: return B0;
case 50: return B50;
case 75: return B75;
case 110: return B110;
case 134: return B134;
case 150: return B150;
case 200: return B200;
case 300: return B300;
case 600: return B600;
case 1200: return B1200;
case 1800: return B1800;
case 2400: return B2400;
case 4800: return B4800;
case 9600: return B9600;
case 19200: return B19200;
case 38400: return B38400;
case 57600: return B57600;
case 115200: return B115200;
case 230400: return B230400;
case 460800: return B460800;
case 500000: return B500000;
case 576000: return B576000;
case 921600: return B921600;
case 1000000: return B1000000;
case 1152000: return B1152000;
case 1500000: return B1500000;
case 2000000: return B2000000;
case 2500000: return B2500000;
case 3000000: return B3000000;
case 3500000: return B3500000;
case 4000000: return B4000000;
}
Example :
int uartFD = uartOpen(4, 9600); // It opens uart 4 with baud rate 9600 and returns a file descriptor to access it.
- *int uartWrite(const int uartFD, const int length, const uint8_t bytes) : This function takes file descriptor, length of data bytes to be transferred and pointer to the array of bytes to be transferred as input and sends it using write system call. It returns 0 if successful and -1 if it fails.
Returns : 0 if successful and -1 if it fails.
Example :
EditText et = (EditText)findViewById(R.id.editText1);
byte[] send = et.getText().toString().getBytes();
int ret = uartWrite(uartFD, send.length+1,send); // It writes array of send bytes via uart.
- *int uartRead(const int uartFD, const int length, uint8_t bytes) : This functions takes file descriptor, length of data bytes to be received and pointer to array to store the bytes received as input and reads data from UART using read system call. It returns 0 if successful and -1 if it fails.
Returns : 0 if successful and -1 if it fails.
Example :
byte[] temp = new byte[2];
int ret = uartRead(uartFD, 1, temp); // It reads 1 byte of data in temp via uart.
- void uartClose(const int uartFD) : This function is used to close UART file descriptor.
Example :
uartClose(uartFD); // It closes uart file descriptor.
###Screenshot of UART android application