cancel
Showing results for 
Search instead for 
Did you mean: 

L9848TR SPI Communication Failing with main ECU (SC123/sc143)

embedded_07
Associate

Hello;
I hope you are doing well. I have IO board on which L9848TR is connected which is controlling 8 LEDs , those LEDs are connected in active low configuration. I need to create low at the out pins of L9848TR to turn on those LEDs. L9848TR operates with SPI chip select (Active High). I checked my hardware board manually everything is working fine. It really is the issue with accessing the L9848TR with my main CPU. it should have been straightforward thing. but its just not working. I am attaching my sample code. please check if someone can help me what I am doing wrong here. or if someone already worked with this before share your experience or some sample code of writing/sending a byte to L9848TR. I will be really thankful to you. 
Main CPU: 
@https://www.all-electronics.de/wp-content/uploads/migrated/document/170407/1f42b1d0153.pdf

L9848TR chip:
https://estore.st.com/en/l9848tr-cpn.html

here is the sample code:

 

//-----------------------------------------------------------------------------
// SPI
//-----------------------------------------------------------------------------
// Below SPI pins are from SC123(main CPU Board)
#define MISO_PIN 28 // SPI serial in pin - B11
#define MOSI_PIN 27 // SPI serial out pin - A12
#define SCK_PIN 19  // SPI clock pin - B12

//-----------------------------------------------------------------------------
// DIGITAL PINS (Enabling IO)
//-----------------------------------------------------------------------------
#define ENABLE_IO 13
#define CS_U1 31

//-----------------------------------------------------------------------------
// HIGH LOW Macro
//-----------------------------------------------------------------------------
#define PIO_HIGH 4
#define PIO_LOW 5
#define LOW 0
#define HIGH 1

void
IO_bearbeiten(void)
{
  BYTE Out, x;
  int Out_port;

  RTX_Sleep_Time(1500);

  Out = 0x00;
  In_alt = 0x00;

  // Hardware einstellen

  Log_eintrag(LOG_MESSAGE, LOG_IO, "Init Hardware ...");
  if (Daten->Ini.Hardware == IO_3001)
  {
    pfe_enable_pio(ENABLE_IO, PIO_LOW); // Low
    pfe_enable_pio(CS_U1, PIO_HIGH);    // High
    pfe_enable_pio(CS_U1, PIO_LOW);     // Low
    spi_init(0, SCK_PIN, MISO_PIN, MOSI_PIN);
    pfe_enable_pcs(0); // 0: don't care (PCS0# is no PIO), PCS0# is active when
                       // I/O address between 000h..1FFh
    In_port = 0x000;
    Out_port = 0x000;
  }

  while (Daten->Tasks_run)
  {
    // Ausgänge
    if (Out != Daten->Io.Out)
    {
      // von aussen gesetzt
      Out = Daten->Io.Out;

      if (Daten->Ini.Hardware == IO_3001)
      {
        // umstellen Bits
        Out = 0;
        x = ~(Daten->Io.Out);

        if (x & 0x01)
          Out |= 0x80;
        if (x & 0x02)
          Out |= 0x40;
        if (x & 0x04)
          Out |= 0x20;
        if (x & 0x08)
          Out |= 0x10;
        if (x & 0x10)
          Out |= 0x08;
        if (x & 0x20)
          Out |= 0x04;
        if (x & 0x40)
          Out |= 0x02;
        if (x & 0x80)
          Out |= 0x01;

        hal_write_pio(CS_U1, HIGH);
        spi_write(&Out, 1);
        hal_write_pio(CS_U1, LOW);

        Out = Daten->Io.Out;
      } else
      {
        outportb(Out_port, ~Out);
      }
    }
  }
}

 

---------------------------------------------------------------------
Kindly let me know if there is anything unclear. 

Thanks 



0 REPLIES 0