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
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