cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Discovery board and TLC5947

VYada.3
Associate II

Hi

I'm new to using STM Microcontrollers and I have the Discovery board as my development board, I have used Arduino religiously and thought I should learn something new.

I have learnt how to modify data registers, for example, turn the 4 LEDs on and off, also get an input from the push button to get the Leds to turn on.

Am now looking at PWM, which I did get to work. I had a previous project which uses these TLC5947 to turn some LEDs on, I used Arduino and it worked fine, since it used PWM I thought I could practice with these. Unfortunately, trying to get it to work with the discovery board isn't working out the way that I want and was wondering if someone can help me.

I know the Arduino has a 16Mhz clock and PWM frequency is 490hz and I know the discovery board is way higher. I just generally don't know where to begin

adfruit has a libaray file which modifys the pwm high and low using the code below

void Adafruit_TLC5947::write() {
  digitalWrite(_lat, LOW);
  // 24 channels per TLC5974
  for (int16_t c = 24 * numdrivers - 1; c >= 0; c--) {
    // 12 bits per channel, send MSB first
    for (int8_t b = 11; b >= 0; b--) {
      digitalWrite(_clk, LOW);
 
      if (pwmbuffer[c] & (1 << b))
        digitalWrite(_dat, HIGH);
      else
        digitalWrite(_dat, LOW);
 
      digitalWrite(_clk, HIGH);
    }
  }
  digitalWrite(_clk, LOW);
 
  digitalWrite(_lat, HIGH);
  digitalWrite(_lat, LOW);
}

Of course, I thought that I could just use the pins on the dsicvoery board to do the same thing, high and low however that doesn't work, don't even know why I thought it would. It uses the Arduino PWM pins and this is where I was stuck.

I even thought maybe logic level shifters would work, but that didn't work either I even used delays, however nothing.

I know the discovery board can use 16Mhz (however if I do that I fell like I should just stick with the Arduino) by modifying the HSI but not 100% sure how to go about that, I would even need to change the pre scale value to make the frequency to 490Hz and change the counter period to 255, again not 100% sure how to go about that I have tried and I think I'm doing something wrong.

any help would be great or am i just wasting my time and to just stick with arduino

Thank you

8 REPLIES 8

The code you show just drives pins high and low, it doesn't use PWM modes.

​On the STM32 you can define the frequency and duty of TIM pins significantly more precisely and broadly than the Arduino implementation.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

You might need delays between GPIO pin transitions here. Presume you haven't checked the timing requirements and don't have a scope.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Which STM32?

What hardware?

The code you've presented looks awful lot like SPI. You can transmit similar sequence also using Synchronous mode of USART.

JW

Hi

i thought since it is just high and low that it would work just by toggling the PD pins

below is what i tried with the delays

void write(void){
	*pPortDOutReg &= ~(1 << 12);
		for (int16_t c = 24 * 1 - 1; c >= 0; c--) {
			 for (int8_t b = 11; b >= 0; b--) {
				   *pPortDOutReg &= ~(1 << 14);
			      if (pwmbuffer[c] & (1 << b)){
			    	  *pPortDOutReg |= (1 << 15);
			      }else{
			    	  *pPortDOutReg &= ~(1 << 15); 
			         *pPortDOutReg |= (1 << 14);
			      }
			      delay();
			    }
			 	delay2();
		}
		*pPortDOutReg &= ~(1 << 14);
		*pPortDOutReg |= (1 << 12);
		*pPortDOutReg &= ~(1 << 12);
		printf("----END---- \n");
}
 
void delay(void){
	for(uint32_t i=0; i < 7500; i++);
}
 
void delay2(void){
	for(uint32_t i=0; i < 225; i++);
}

I used a scope to measure against the Arduino, when I initialize delay () where it is I have to set the delay to 7500, so PD15 matches what come out of the arduino. However, when I italize delay2 () for 255 where it is PD14 matches, however it screws up the delay for PD15 and vice versa

Hi

im using STM32F407G-DISC board connected to this board

https://www.adafruit.com/product/1429

i just checked and it looks like it is an SPI interface, of course since im learning would you know a good tutorial on SPI with the discovery board as i have no idea where to start

Thank you

Hi

it says the TLC5947 has to have 15Mhz SCLK im using SPI1 which i belive is connected to APB1 periphal clock which is at 42Mhz i can prescale the baud rate but by the factor of 2 which means i can not get it to 15Mhz. if i divide by 2 i get 21 is i divide by 4 i get 10.

how woulds i go about this

Thank you

The TLC5947 can be used in cascade, i.e. several in a row, up to max. 15MHz, up to 30MHz if it is only one. In both cases it is the maximum clock frequency, not the exact one.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
VYada.3
Associate II

ok im a complete idiot all i had to do was lower the APB1 periphal clock by a factor of 8 and just use the PD pins connected to the on board LEDs as the _clk, _dat and _lat. thank you @Peter BENSCH​ for reminding me that those are the max MHz needed not the exact ones