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

Bits lost while receiving serial data

This is in connection with my old post http://www.keil.com/forum/20496/

I got great help here. Now I can read serial bit stream into a 32bit long, split it in 4 bytes & after some conversion can send the captured data to my 16*2 LCD. I have done it but some of the input bits were lost while doing it & I got garbage data. The real story is like this:

I want to capture data from a device & display it. The MCU in the device sends the display data to MM5452 LCD controller (www.ti.com/.../snls367b.pdf) which is displayed on 3 1/2 LCD display. I am trying to capture the data from the input pins of the LCD controller which are sent by the MCU in the device.

The LCD controller has 3 input pins. One is DATA ENABLE, another is CLOCK & third one is DATA. DATA is latched on high going CLOCK pulse provided DATA ENABLE is low. The first data bit is start bit which is always 1. Next 35 bits are real data bits out of which first 32 bits are needed. I think last 3 bits are for data format compatibility with other similar controllers.

I inverted the clock pulse & used INT0 to detect it. In the ISR, I read the data bit & saved it in 32bit long. As I got garbage data, I checked the signals on CRO. The clock cycle width was 10uS. I am using 24Mhz crystal on 89S52 so single-cycle instruction will take 0.5uS. That means in my interrupt routine maximum of 20 single-cycle instructions are allowed, which I think it is not possible (at least for me). Because I will need to keep track of START BIT, DATA ENABLE & number of bits collected so as to differentiate the data chunk. Further conversion can be done out of the ISR.

Is it possible to solve this issue on different micro-controller such as AVR or ARM?

Sorry for long post, but I thought I should give you as much information as possible in the first go.

Parents
  • Sorry for posting too late. Actually I was trying to correct some problems in my old ISP programmer by Atmel(schematics as in isp_c_v5 & AT89ISP software). Still it is not working satisfactory, sometimes it works sometimes not. This programmer has support for AT89S8253 which I want to use now(for SPI feature).

    ONE GOOD NEWS IS THAT I HAVE SUCCEEDED IN CAPTURING THE CORRECT DATA BY USING EXTERNAL SHIFT REGISTERS.

    Per Westermark, as per your suggestion now I am trying to capture the same data using SPI port of AT89S8253. I have not used the SPI port before. I have changed the code which was originally written for 89S52.

    In the initialization I added following.

            P1 = 0xFF;      //P1.4-P1.7 should be high before SPI is enabled
            SPCR |= 0x40;   //Set SPE bit to enable SPI (6th bit)
            SPCR &= 0xEF;       //clear MSTR bit (4th bit)
            SPCR |= 0x80;   //Set SPIE bit to enable SPI interrupt(7th bit)
    
    //      SPCR = 0xC0;    //equivalent to above commands???
            ES = 1;         //enable serial interrupt, as it is shared by SPI
            EA = 1;         // Enable Global Interrupt Flag
    

    In the serial ISR I wrote

    void com_isr (void) interrupt 4
    {
    /*------------------------------------------------
    Received data interrupt.
    ------------------------------------------------*/
    if (RI != 0)
      {
      RI = 0;
      }
    
    /*------------------------------------------------
    Transmitted data interrupt.
    ------------------------------------------------*/
    if (TI != 0)
      {
      TI = 0;
      }
    
    if ((SPSR & 0x80) !=0 )                     //if SPIF bit is set
            {
            debug_led2=!debug_led2;
            SPSR &= 0x7F;                       //clear SPIF bit
            serial_data=SPDR;               // read receive data
            }
    
    }
    

    The problem is that, though a number of bytes should be received, the debug LED is toggled only once. Can you please help?

    I have wired /DataEnable to SS pin, Clock to SCK pin & Data to MOSI pin.

Reply
  • Sorry for posting too late. Actually I was trying to correct some problems in my old ISP programmer by Atmel(schematics as in isp_c_v5 & AT89ISP software). Still it is not working satisfactory, sometimes it works sometimes not. This programmer has support for AT89S8253 which I want to use now(for SPI feature).

    ONE GOOD NEWS IS THAT I HAVE SUCCEEDED IN CAPTURING THE CORRECT DATA BY USING EXTERNAL SHIFT REGISTERS.

    Per Westermark, as per your suggestion now I am trying to capture the same data using SPI port of AT89S8253. I have not used the SPI port before. I have changed the code which was originally written for 89S52.

    In the initialization I added following.

            P1 = 0xFF;      //P1.4-P1.7 should be high before SPI is enabled
            SPCR |= 0x40;   //Set SPE bit to enable SPI (6th bit)
            SPCR &= 0xEF;       //clear MSTR bit (4th bit)
            SPCR |= 0x80;   //Set SPIE bit to enable SPI interrupt(7th bit)
    
    //      SPCR = 0xC0;    //equivalent to above commands???
            ES = 1;         //enable serial interrupt, as it is shared by SPI
            EA = 1;         // Enable Global Interrupt Flag
    

    In the serial ISR I wrote

    void com_isr (void) interrupt 4
    {
    /*------------------------------------------------
    Received data interrupt.
    ------------------------------------------------*/
    if (RI != 0)
      {
      RI = 0;
      }
    
    /*------------------------------------------------
    Transmitted data interrupt.
    ------------------------------------------------*/
    if (TI != 0)
      {
      TI = 0;
      }
    
    if ((SPSR & 0x80) !=0 )                     //if SPIF bit is set
            {
            debug_led2=!debug_led2;
            SPSR &= 0x7F;                       //clear SPIF bit
            serial_data=SPDR;               // read receive data
            }
    
    }
    

    The problem is that, though a number of bytes should be received, the debug LED is toggled only once. Can you please help?

    I have wired /DataEnable to SS pin, Clock to SCK pin & Data to MOSI pin.

Children
No data