[En-Nut-Discussion] UART_FRAMINGERROR occurring randomly during RS232 communication

René Becker r.becker at futurechemistry.com
Fri Dec 17 15:54:19 CET 2010


Hi all,

I am new to this list, so if I am violating any of the list rules, please
let me know and I will try to change my behaviour!

My case is this: I have a working application using Nut/OS 4.3.2 on a
AT91SAM7X256, performing some basic functions over several threads. I am
controlling a syringe pump via RS232, using basic UART functionality,
sending ascii commands without waiting for acknowledge signals.

Problem: once every (rough guess) 5000 writes the _write() routine times
out, throws a *framing error* and TX buffer stays non-empty. I tried
increasing the TX buffer size to 128, but to no avail. What could be the
problem?

Below is some (minimal) code, showing what I am doing.

Greetings and thanks in advance,
René Becker


*Initialising the RS232 stream:*

// initialize RS-232 interface:
NutRegisterDevice(&DEV_UART1, 0, 0);
rs232 = fopen(DEV_UART1_NAME, "w+b");

// default TX buffer size = 64 (WM_Hi 56, WM_Lo 40)
// increase to twice this size:
u_long parm;
parm = 128;
_ioctl(_fileno(rs232), UART_SETTXBUFSIZ, &parm);
parm = 80;
_ioctl(_fileno(rs232), UART_SETTXBUFLWMARK, &parm);
parm = 112;
_ioctl(_fileno(rs232), UART_SETTXBUFHWMARK, &parm);

// set baudrate:
u_long baud = 9600;
_ioctl(_fileno(rs232), UART_SETSPEED, &baud);

// set write timeout:
u_long wrto = UART_WRITETIMEOUT;
_ioctl(_fileno(rs232), UART_SETWRITETIMEOUT, &wrto);


*Another routine writes to the buffer:*

void pump_writef(const void * buffer, int size)
{
// flush the buffer - start sending to the pump:
if (_write(_fileno(rs232), buffer, size) < 0 || _write(_fileno(rs232), 0, 0)
< 0 || fflush(rs232) == EOF)
{ // an error has occured writing to the pump
// get UART status:
//_ioctl(_fileno(rs232), UART_GETSTATUS, &parm);
// send error message:
char message [MSG_SIZE];
//sprintf(message, "E %08X PumpCommError on <%s>, UART_STATUS=%08X.\n\r",
PUMP_ERROR, (char *) buffer, (unsigned int) parm);
sprintf(message, "E %08X PumpCommError on <%s>.\n\r", PUMP_ERROR, (char *)
buffer);
USBSendMessage ((unsigned char*) message);
}
NutSleep(100);
}



More information about the En-Nut-Discussion mailing list