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

"Transmit Buffer Interrupt" in XC16x

Hi,

I am using Keil to write an ASC0 program for XC16x with the concept "Transmit Buffer Interrupt". In the link the manual is to be found (chapter 19.2.3): www.infineon.com/.../xc164_um_v1.2_2006_03_per.pdf The idea looks like this: The number of FIFO is 8 and the number of bytes to trigger an interrupt can be set by the user, for example 3. If the number of bytes in the FIFO reaches 3, an interrupt will be triggered. In the ISR the user can put more bytes in the FIFO. In my example there are two functions:

ASC0_vSendData_LCD(): Send function
ASC0_viTxBuffer(): ISR


Number of bytes to trigger = 3

Global Variables:

unsigned char rest_number;      //how many bytes must still be sent.
unsigned char *lcd_data;                // data bytes

The function ASC0_vSendData_LCD() can be called like this:

unsigned char buf1[] = {0xAA, 0x55, 0x00, 0x00, 0x00, 0x00, 0x41, 0xCC, 0x33, 0xC3, 0x3C};
lcd_data = &buf1[0];
ASC0_vSendData_LCD(lcd_data, 11);


And the ISR will be called if number of bytes > 8.

I just want to know if there are any potential errors in my code to lead to lose bytes.

void ASC0_vSendData_LCD(unsigned char *lcd_data, unsigned char lcd_number)
{
        unsigned char i = 0;
        // no ISR needed if data bytes <= 8
        if (lcd_number <= 8)
        {
                for (i = 0; i < lcd_number; i++)
                        ASC0_vSendData(lcd_data[i]);
        }
        // the first 8 bytes are sent
        else
        {
                for (i = 0; i < 8; i++)
                        ASC0_vSendData(lcd_data[i]);
                rest_number = lcd_number - 8;
        }
}

void ASC0_viTxBuffer(void) interrupt ASC0_TBINT using RB_LEVEL15
{
        static unsigned char times;     // how many times is this ISR called
        unsigned char i = 0;
        // leave ISR if no more data bytes
        if(rest_number == 0)
                return;
        // all the data bytes can be sent if they are less than 5
        if (rest_number <= 5)
        {
                for (i = 0; i < rest_number; i++)
                        ASC0_vSendData(lcd_data[8 + 5*times + i]);      // the position of data bytes
                rest_number = 0;
                times = 0;
        }
        // this ISR shall be called again because too many data bytes (> 5)
        else
        {
                for (i = 0; i < 5; i++)
                        ASC0_vSendData(lcd_data[8 + 5*times + i]);
                rest_number -= 5;
                times++;
        }
} //  End of function ASC0_viTxBuffer

Thank you
Senmeis