microcontroller bootloader in C

Discussion in 'C++' started by Thomas Baier, Aug 16, 2004.

  1. Thomas Baier

    Thomas Baier Guest

    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
    Thomas Baier, Aug 16, 2004
    #1
    1. Advertising

  2. Thomas Baier wrote:
    > 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
    Victor Bazarov, Aug 16, 2004
    #2
    1. Advertising

  3. Thomas Baier

    Thomas Baier Guest


    > 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?
    Thomas Baier, Aug 16, 2004
    #3
  4. Thomas Baier <> spoke thus:

    > 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.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Aug 16, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SneakerNet
    Replies:
    0
    Views:
    661
    SneakerNet
    Sep 1, 2003
  2. kitkat
    Replies:
    2
    Views:
    2,466
  3. Dave

    Xilinx bootloader help...

    Dave, Aug 29, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,789
    David Ashley
    Sep 5, 2006
  4. Replies:
    4
    Views:
    412
    David Ashley
    Aug 24, 2006
  5. internet

    Bootloader Problem

    internet, Jun 26, 2009, in forum: VHDL
    Replies:
    0
    Views:
    454
    internet
    Jun 26, 2009
Loading...

Share This Page