Electronics > Projects, Designs, and Technical Stuff

LED drivers, How to connect them to Normal SPI

<< < (3/3)

SiliconWizard:
Just as an added note if no hardware change is possible and if using SPI is not an option or wouldn't bring significant benefits due to this LE signal and how it must (if I got it well from the datasheets, but didn't look too deeply) apparently be toggled right in the middle of the serial communication: we haven't seen your code, but I think there are probably a number of ways to improve your bit-banging approach (including not making it blocking) so that its relative inefficiency wouldn't be a problem in your code.

My assumption here is that 1/ LED driving itself is not that time-critical if it's just for viewing purposes - to be confirmed -  and 2/ the way you currently bit-bang to the LED driver is likely blocking, and thus makes it impossible to execute anything else on the MCU until it's completely done. If 1/ is true, you could just implement the bit-banging in some timer interrupt for instance, "sending" just one bit at a time at whatever rate is convenient and still meets your requirements, but obviously as slow as possible. Time spent in this interrupt would be minimal. MCU could execute anything else while the communication is under progress, which, unless again updating the status of the LEDs should be very fast (useless if it's only a visual indicator), is probably your main concern here.

ali_asadzadeh:
Thanks for the feedback, The LED driver part is not allowed to change, but everything else is possible, also It should be on a low end MCU, because of the price

This is the STM32 bit-bang code,


--- Quote ---#define RGB_LE_init                  //GPIO_SetDir(0,11,GPIO_DIR_OUTPUT) //RGB_LE
#define RGB_LE_0                     HAL_GPIO_WritePin(GPIOF,GPIO_PIN_0,GPIO_PIN_RESET)//LE0
#define RGB_LE_1                     HAL_GPIO_WritePin(GPIOF,GPIO_PIN_0,GPIO_PIN_SET)//LE1

#define RGB_SDO_init               

#define RGB_SDI_init               
#define RGB_SDI_0                     HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET)//SDI    0                        
#define RGB_SDI_1                     HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET)//SDI    1                        

#define RGB_CLK_init               
#define RGB_CLK_0                     HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET)//SCK    0               
#define RGB_CLK_1                     HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET)//SCK    1   

void init_STP1612PW05(void)
{
   

   //set outputs
   RGB_LE_init;
   
   RGB_SDO_init;
   RGB_SDI_init;
   RGB_CLK_init;
   
   RGB_LE_1;
   
}


void STP1612PW05_write(void)
{
   int i=0;
   uint16_t RGB_Data_temp[16];
   for(i=0;i<16;i++)
      RGB_Data_temp=RGB_Data;
   
   //Load first 15 data
   for(int j=0;j<15;j++)
   {
      for(i=0;i<16;i++)
      {
         RGB_LE_0;   
         
         if(i==15)
            RGB_LE_1;

         RGB_CLK_0;
         if(RGB_Data_temp[j] & 0x8000)
            RGB_SDI_1;
         else
            RGB_SDI_0;
         
         
         
         RGB_CLK_1;
         RGB_Data_temp[j] <<= 1;
      }
   }
   //osDelay(1);
   //Global latch all data
   for(i=0;i<16;i++)
   {
      
      RGB_LE_0;   
      
      if(i==15 || i==14)
         RGB_LE_1;

      
      RGB_CLK_0;
      if(RGB_Data_temp[15] & 0x8000)
         RGB_SDI_1;
      else
         RGB_SDI_0;
      
      
      
      RGB_CLK_1;

      RGB_Data_temp[15] <<= 1;
   }
}


--- End quote ---

If it can be done efficiently with DMA and GPIO only, it would be nice! since GPIO and DMA is almost free on any cortex M part.

NorthGuy:

--- Quote from: ealex on August 07, 2019, 12:22:24 pm ---- synchronize 2 SPI channels, if possible on your CPU with the same clock and mode, one of them handles SDI and the other handles LE - you will need 2x16 bit words for each byte

--- End quote ---

Make one SPI master, forward the clock from it to the other SPI.

Make the second SPI slave, and use its MISO to output LE as needed.

This will be perfectly synchronized and DMA-able.

SiliconWizard:

--- Quote from: ali_asadzadeh on August 07, 2019, 02:37:43 pm ---Thanks for the feedback, The LED driver part is not allowed to change, but everything else is possible, also It should be on a low end MCU, because of the price

This is the STM32 bit-bang code,

--- End quote ---

Confirms that it's blocking.
As I said above, making it non-blocking is largely possible even with no DMA, and not very difficult.

Now you have several different options. Up to you to select the one that can be implemented on your MCU and that you feel comfortable with.

ali_asadzadeh:

--- Quote ---Confirms that it's blocking.
As I said above, making it non-blocking is largely possible even with no DMA, and not very difficult.
--- End quote ---

Thanks, But how?



--- Quote ---Make one SPI master, forward the clock from it to the other SPI.

Make the second SPI slave, and use its MISO to output LE as needed.

This will be perfectly synchronized and DMA-able.
--- End quote ---
That sound a good option,but pricey in terms of SPI usage.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod