microcontroller bootloader in C

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
 
V

Victor Bazarov

Thomas said:
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.

[...]

You appear to be lost. This is a C++ newsgroup. comp.lang.c is just
down the corridor, on the left. Keep in mind, though, that hardware
programming is not part of the language, so you can still be off-topic
there.

V
 
T

Thomas Baier

You appear to be lost. This is a C++ newsgroup. comp.lang.c is just

well I know but any answer in C++ or in C would be helpful for me, I'll post
in comp.lang.c too
down the corridor, on the left. Keep in mind, though, that hardware
programming is not part of the language, so you can still be off-topic
there.

yeah, that's right, too, but I didn't find any newsgroup matching my topic.
Can you point me to some, please?
 
C

Christopher Benson-Manica

Thomas Baier said:
well I know but any answer in C++ or in C would be helpful for me, I'll post
in comp.lang.c too
Don't.

yeah, that's right, too, but I didn't find any newsgroup matching my topic.
Can you point me to some, please?

comp.arch.embedded, perhaps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top