-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Hi,
I'm getting intermittent system freezes on multiple new Raspi B+ V1.2 boards
running Raspian / Linux 3.18.7+ and the actual module driver.
SysRq doesn't work; no kernel dump, nothing logged.
Following test code will freeze my Pi in a matter of minutes.
- There's nothing connected to the RasPiComm Board.
- Code is running fine with an external USB RS485 converter
#include <stdio.h> /* included for printf() */
#include <fcntl.h> /* included for O_RDWR, O_NOCTTY and O_NDELAY */
#include <termios.h> /* included for functions and defines used in set_interface_attribs */
#include <string.h> /* included for memset */
#include <unistd.h>
#include <errno.h>
#define READER "/dev/ttyRPC0"
//#define READER "/dev/ttyUSB0"
int comport;
unsigned char mesg1[]= {0x01,0x02,0x03,0x04};
/*
Source:
http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c
*/
int set_interface_attribs (int fd, int speed, int parity)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0)
{
printf("error using tcgetattr\n");
return -1;
}
cfsetospeed (&tty, speed);
cfsetispeed (&tty, speed);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~IGNBRK; // ignore break signal
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
printf("error from tcsetattr\n");
return -1;
}
return 0;
}
int main(int argc, char** argv)
{
fprintf(stdout,"Test for RasPiComm\n");
fprintf(stdout,"Open Port %s...\n", READER);
if ( (comport = open(READER, O_RDWR | O_NOCTTY | O_NDELAY)) < 0 )
{
fprintf(stdout,"failed.\n");
fprintf(stdout,"possible causes:\n");
fprintf(stdout,"1) the raspicomm device driver is not loaded. type 'lsmod' and verify that you 'raspicommrs485' is loaded.\n");
fprintf(stdout,"2) the raspicomm device driver is in use. Is another application using the device driver?\n" );
fprintf(stdout,"3) something went wrong when loading the device driver. type 'dmesg' and check the kernel messages\n");
return -1;
}
printf("successful. fd=%i\n", comport);
// configure the port
if (set_interface_attribs(comport, B19200, PARENB) < 0)
{
fprintf(stdout,"Error configuring RS485 Port.\n");
return -2;
}
int count=0;
while(1)
{
fprintf(stdout,"Sending String \n");
int written=write(comport,mesg1,4);
if(written<4)
{
fprintf(stdout,"Write ERROR!");
}
if(count%20==0)
{
fprintf(stdout,"\nKLICK\n");
count=0;
}
count++;
usleep(10000);
}
//Never reached
close(comport);
}
Metadata
Metadata
Assignees
Labels
No labels