T
Thomas Baier
Hi there,
I've got a little problem while working on a bootloader for a C164
microcontroller. The microcontroller gets the data over the serial port.
I've already implemented some functions that transmit some vmc and hex
files to the controller while there is a OS running on it. But now I'd like
to transmit my one bootstrap loader and I've got some problems with the
serial communication in C.
Here's my code to configure the serial port under linux (I'm working on Suse
Linux prof. 9.0):
int openport(char* device)
{
int fd;
struct termios *current; //IO-Settings
struct termios options;
fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1)
return -1;
bzero(&options, sizeof(options));
tcgetattr(fd, &options);
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag = B19200 | CRTSCTS | CSTOPB | CLOCAL | CREAD;
//8 databits, no paritybit, 1 stopbit
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
return (fd);
}
And now I simply want to transmit a zero byte (say 1 startbit, 8 zero bits
and 1 stopbit):
int comport = openport("/dev/ttyS0");
write(comport,0,1);
usleep(250);
unsigned char cbuf = 0;
while(read(sfd, &cbuf, 1)>0) {
printf("%i\t",(int) cbuf);
}
but the microcontroller doesn't answer. It should return an identification
byte, but I do not receive anything at all. I've got some software for
windows that works fine (but only under windows) and I spied on its
communication between itself and the comport and got this as the first two
lines:
#00 //out - zero byte
#F8#D5 //in - identification byte
So there can't be a failure at the microcontroller.
Thanks for any help.
Thomas
I've got a little problem while working on a bootloader for a C164
microcontroller. The microcontroller gets the data over the serial port.
I've already implemented some functions that transmit some vmc and hex
files to the controller while there is a OS running on it. But now I'd like
to transmit my one bootstrap loader and I've got some problems with the
serial communication in C.
Here's my code to configure the serial port under linux (I'm working on Suse
Linux prof. 9.0):
int openport(char* device)
{
int fd;
struct termios *current; //IO-Settings
struct termios options;
fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1)
return -1;
bzero(&options, sizeof(options));
tcgetattr(fd, &options);
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag = B19200 | CRTSCTS | CSTOPB | CLOCAL | CREAD;
//8 databits, no paritybit, 1 stopbit
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
return (fd);
}
And now I simply want to transmit a zero byte (say 1 startbit, 8 zero bits
and 1 stopbit):
int comport = openport("/dev/ttyS0");
write(comport,0,1);
usleep(250);
unsigned char cbuf = 0;
while(read(sfd, &cbuf, 1)>0) {
printf("%i\t",(int) cbuf);
}
but the microcontroller doesn't answer. It should return an identification
byte, but I do not receive anything at all. I've got some software for
windows that works fine (but only under windows) and I spied on its
communication between itself and the comport and got this as the first two
lines:
#00 //out - zero byte
#F8#D5 //in - identification byte
So there can't be a failure at the microcontroller.
Thanks for any help.
Thomas