I am trying to set the baud rate of one of the Beaglebone's serial
port to 31250, the baud rate for Midi. 31250 is a non-standard baud
rate and I am trying to write a simple program to set the rate for /
dev/ttyO1. The program outputs the "Error: could not set
custom_divisor" message, as ioctl returns -1 after the custom_divisor
has been set.
#define CUST_BAUD_RATE 31250
int main()
{
int fd = open ("/dev/ttyO1", O_RDWR);
if ( fd == -1 )
{
cout << "Error opening device" << endl;
return -1;
}
struct serial_struct ser_info;
int i = ioctl(fd, TIOCGSERIAL, &ser_info);
if ( i < 0 )
cout << "Error: could not get ioctl" << endl;
ser_info.flags = ASYNC_SPD_CUST | ASYNC_LOW_LATENCY;
ser_info.custom_divisor = ser_info.baud_base / CUST_BAUD_RATE;
i = ioctl(fd, TIOCSSERIAL, &ser_info);
if ( i < 0 )
cout << "Error: could not set custom_divisor" << endl;
close (fd);
return 0;
}
Any suggestions?