I2C sending random bytes and looping main() EFM8

Thread Starter

GoExtreme

Joined Mar 4, 2018
52
Trying EFM8UB10 platform and making a current sensor with oled screen. Both I2C. When uploading data array to display. It seems to send random bytes (sometimes sending bytes from previous function) and makes main loop. On analyzer it shows random bytes and repeats. What an cause this issue?

Main has just display();

Code:
void display(void)
        {
        uint16_t i;
   
        I2C_MasterWrite(OledDisp); //  sets position on lcd

        for (i = 0; i < 512; i++) {
            SSDData(0x40); //data
            SSDData(0x00); // 0 clear
       
            }
         }
]
SendByte:
Code:
void SSDData(uint8_t c)
{

    TARGET = 0x3C;    //Slave Address
    SMB_DATA_OUT[0] = c;// Load first data byte
    NUM_BYTES_WR = 1; // Number of bytes to transmit

    while(SMB_BUSY);                    // Wait for SMBus to be free.
     SMB_BUSY = 1;                       // Claim SMBus (set to busy)
     SMB_RW = 0;                        // Write
     SMB0CN0_STA = 1;    //initiate the transaction by setting the start-condition bit
     SFRPAGE = SMB0_PAGE;
     while(SMB_BUSY);
}
Smbus interrupt send:
Code:
SI_INTERRUPT(SMBUS0_ISR, SMBUS0_IRQn)
{
   bool FAIL = 0;                       // Used by the ISR to flag failed
                                       // transfers

   static uint8_t sent_byte_counter;
   static uint8_t rec_byte_counter;

   if (SMB0CN0_ARBLOST == 0)           // Check for errors
   {
      // Normal operation
      switch (SMB0CN0 & 0xF0)          // Status vector
      {
         // Master Transmitter/Receiver: START condition transmitted.
      case SMB_MTSTA:
                  SMB0CN0_STA = 0;           // Manually clear START bit
                  SMB0CN0_STO = 0;           // Manually clear STOP bit
                  SMB0DAT = (TARGET<<1)|SMB_RW;    // Load R/W bit
                  SMB0CN0_SI = 0;                     // Clear interrupt flag
                  sent_byte_counter = 0;             // Reset W byte counter
                  rec_byte_counter = 1;                 // Reset R byte counter
                 break;

              // Master Transmitter: Data byte transmitted
              case SMB_MTDB:
                 if (SMB0CN0_ACK)           // Slave SMB0CN0_ACK? After Address
                 {
                    if (SMB_RW == WRITE)    // If this transfer is a WRITE,
                    {
                      if (sent_byte_counter == NUM_BYTES_WR) // If byte count from array
                      {
                      SMB0CN0_STO = 1;   //transmit stop condition
                      SMB_BUSY = 0;     // And free SMBus
                      SMB0CN0_SI = 0;   // Clear interrupt flag
                         }
                          else
                              {
                                 SMB_DATA_OUT++;    //increment pointer that points at data to be transmitted
                                  SMB0DAT = *SMB_DATA_OUT;    //write next byte to SMBus data register
                                  sent_byte_counter++;

                              }
               }
               else {}                 // If this transfer is a READ,
                                       // proceed with transfer without
                                       // writing to SMB0DAT (switch
                                       // to receive mode)

            }
            else                       // If slave NACK,
            {
               SMB0CN0_STO = 1;        // Send STOP condition, followed
               SMB0CN0_STA = 1;        // By a START
                         // Indicate error
            }
            break;
}
Attaching analyzer reading. You can see its sending proper bytes to config the screen but then it sends all kinds of bytes and loops.
 

Attachments

Top