This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can't get TI flag to be set when writing into SBUF

Hi,

I'm trying to simulate working of a UART.
When I write into SBUF, the TI flag doesn't
go high even though I have enabled interrupts.

Is there any way I can simulate it using SOUT VTREG. can't find example how to use SOUT.

Parents
  • hi,

    assume you have wrote something like that:

    void serial() interrupt 4
    {
    //... receive code
    //...
    if (TI == 1)
    {
       TI = 0;
       SBUF=0x34;
    }
    

    But I can't see the TI flag raise when I try reading SOUT or writing to SBUF.

    May I ask: how long do you wait for it?
    You should understand that TI flag is set only after transfer has been completed. At 600 baud, 10 bits transfer takes about 17ms. And all this time TI flag is zero.

    By the way, your initialization routine is not correct. If OSC freq is 20MHz then:
    baudrate = 20000000/32/12/(0x100-0x87) ~= 430baud.

    Regards,
    Oleg

Reply
  • hi,

    assume you have wrote something like that:

    void serial() interrupt 4
    {
    //... receive code
    //...
    if (TI == 1)
    {
       TI = 0;
       SBUF=0x34;
    }
    

    But I can't see the TI flag raise when I try reading SOUT or writing to SBUF.

    May I ask: how long do you wait for it?
    You should understand that TI flag is set only after transfer has been completed. At 600 baud, 10 bits transfer takes about 17ms. And all this time TI flag is zero.

    By the way, your initialization routine is not correct. If OSC freq is 20MHz then:
    baudrate = 20000000/32/12/(0x100-0x87) ~= 430baud.

    Regards,
    Oleg

Children