STM32F4 - Fade and Loop Debugging Help
Greetings,
I have been working with the STM32F407ZG and a KnobG Click from MikroElectronica. I read the datasheet for the PCA9956B and have managed to address the device successfully at the address of 0x70. Now then according to the usage I have seen in the example code (which is severely abstracted and references heavily several library documents), it seems like they set all the LED outputs to full gain and then use a switch case (which seems to somehow default to 1) and all LED lights glow brightly. I have tested their code on my hardware so I know that it works. However, due to a lack of understanding the data sheet I have not succeeded in making that happen yet. I have however, managed to get the first LED to come on as have directly addressed that register (see below code snippet).
void KNOB_LED1_On(void){
uint8_t data[2];
data[0] = 0x0A;
data[1] = 0x10;
HAL_I2C_Master_Transmit(&hi2c1, KNOB_ADDR, data, 2, HAL_MAX_DELAY);
}
Question 1: Why does my fade function appear to work in a saw tooth manner? I wrote the code trying to get it to fade in and out smoothly. Instead it just climbs to full brightness and then goes off and starts over.
void KNOB_LED1_Fade(void){
uint8_t data[2];
data[0] = 0x0A; // The LED control register address or whatever the specific command is for your LED
for(uint8_t i = 0; i <= 0xFF; i++) { // Fading in
data[1] = i; // Set brightness
HAL_I2C_Master_Transmit(&hi2c1, KNOB_ADDR, data, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Around 4ms delay for the fade in to take half a second
}
for(int i = 0xFF; i >= 0; i--) { // Fading out
data[1] = i; // Set brightness
HAL_I2C_Master_Transmit(&hi2c1, KNOB_ADDR, data, 2, HAL_MAX_DELAY);
HAL_Delay(10); // Around 4ms delay for the fade out to take half a second
}
}
Question 2: I put the above code snippet in the initialization portion of the code before the loop. Why is it that the LED continues to fade? I would expect that it would have only occurred once.
Question 3: With my STLINKv3 in hand, what section of the debugger perspective should I be looking for to ascertain why the loops continue to happen?
