configuring TLC5490 library with STM32

Post here first, or if you can't find a relevant section!
Post Reply
vj01
Posts: 3
Joined: Tue Apr 27, 2021 12:49 pm

configuring TLC5490 library with STM32

Post by vj01 »

Hi
Do apologizes if this is in the wrong section been a while since i posted on this. I had an Arduino project which used the TLC5940 Library to control multiple Led’s which worked great, however I wanted to use the STM32 to do the exact same. I got the STM32 to work with the Arduino IDE, however I can’t seem to get the library to work, of course I do understand that they are completely different (things need to be changed), I just don’t know how to tackle this, so thought I would ask if anyone could give me so advice
Thank you
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: configuring TLC5490 library with STM32

Post by fpiSTM »

Well looking quickly it seems not so easy as there is several register access for AVR or Teensy.
If you used the STM32 core you can have a look to the HardwareTimer API but don't know if this will fit properly all the required stuff:
https://github.com/stm32duino/wiki/wiki ... er-library
vj01
Posts: 3
Joined: Tue Apr 27, 2021 12:49 pm

Re: configuring TLC5490 library with STM32

Post by vj01 »

Hi

i figured this wouldnt be easy at all

i did find this however not sure how to implement it using the information from here

https://github.com/bkarl/tlc5940stm32
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: configuring TLC5490 library with STM32

Post by ag123 »

i took a look at the spec
https://www.ti.com/lit/gpn/tlc5940
as well as the code for the stm hal based library.
the main thing is that actually what is used is spi
the timer seemed to be used for inserting us delay.
arduino api delay() would do that in milliseconds.
if you can use arduino's delay that causes gaps of at least 1ms, the delay() function exists.
if you need microseconds. replace that delay in the tlc lib for stm32 hal with
https://github.com/stm32duino/Arduino_C ... ing_time.h

Code: Select all

delayMicroseconds(uint32_t us)
and those timer codes in main.c can probably be omitted as it seemed to provide just this us delay() function.
main.c and main() isn't needed.
those codes goes into setup() and loop() based on whether you are going to run it once or repeatedly.

for spi there are about 2 ways to try
there is the arduino SPI interface
https://github.com/stm32duino/wiki/wiki/API#spi
codes like
https://github.com/bkarl/tlc5940stm32/b ... tlc.c#L114

Code: Select all

void writeTLC(uint8_t data)
{
    SPI_I2S_SendData(tlcConf.spi, data);
    while (SPI_I2S_GetFlagStatus(tlcConf.spi, SPI_I2S_FLAG_TXE) == RESET);
}
could look like

Code: Select all

void writeTLC(uint8_t data)
{
	SPI.transfer(data);
}
that whole chunk of tlc init codes like
https://github.com/bkarl/tlc5940stm32/b ... /tlc.c#L54

Code: Select all

//init all GPIOs, timers, spi...
void initTLC(TLC_InitStruct* tlc)
{
    clkCnt = 0;
    tlcConf = *tlc;

    SPI_InitTypeDef SPI_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    /*****************************************************
                        INIT GPIOs
    ******************************************************/
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Pin = tlcConf.pinBlank | tlcConf.pinXLAT;
    GPIO_Init(tlcConf.gpioCntrl, &GPIO_InitStructure)
 ...
could look like

Code: Select all

SPI.begin(cs_pin);
uint32_t frequency = 10000000;  //10 Mhz
SPI.beginTransaction(SPISettings(frequency, MSBFIRST, SPI_MODE0));
the most tricky part would be those modes and settings which may not literally work out of box.

this is provided you are using the default spi pins e.g. SPI 1 (say

Code: Select all

 #define CS			PA4
 #define CLK		PA5
 #define MISO		PA6
 #define MOSI		PA7

for your board check the pin specs for spi on the mcu datasheet
https://github.com/stm32duino/wiki/wiki/API#spi

--------
the alternate way could be to leave the hal spi codes there and try to use it if the calls to hal compiles without errors

hope it helps
Post Reply

Return to “General discussion”