2019-05-21 10:03 AM
Hello!
I am just getting started with STM32 universe. I've already finished my first project using the IDE SW4STM32 and I board I've designed using the STM32F070CBT. I've also used STM32CubeMX to generate the basic code.
I wanted to keep using this board, as it's fully tested and all the hardware seems to work fine. But I just found a problem trying to implement a way to send a break signal before sending the DMX frame.
I'm using __HAL_UART_DISABLE(&huart1) and __HAL_UART_ENABLE(&huart1) to try to manage the TX1 (PA9) pin, but even though I've tried to just do a simple blink, I can't get any control. It's not doing the break signal at all.
__HAL_UART_DISABLE(&huart1);
HAL_GPIO_WritePin(TX1_Port, TX1_Pin, 0);
delay_us(150);
HAL_GPIO_WritePin(TX1_Port, TX1_Pin, 1);
delay_us(12);
__HAL_UART_ENABLE(&huart1);
HAL_UART_Transmit(&huart1,(uint8_t *)DMX_test,3,0xFFFF);
I am a bit desperate as it's the only detail I'm missing to finish this project. I'm sure it's because I'm not able to send the break signal. Any comments about how can I be able to use the PA9 pin as a normal GPIO to manage the break signal and then configure it again to send the DMX frame? Maybe I am missing something, it should be very simple but it isn't. I would like to avoid to make any change at the hardware if it's possible...
Thank you very much!
A
Solved! Go to Solution.
2019-05-22 12:55 PM
This is something which is a bit more complex than clicking in Cube/CubeMX allows, so you might need to resort to register level programming.
So, get your original program, change the pin's MODE from AF to OUT
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos); // 01: General purpose output mode
and then set the pin's output level as you wish, wait, and then change back from OUT to AF
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (2 << GPIO_MODER_MODER9_Pos); // 10: Alternate function mode
There may be Cube/HAL/LL incantations for this or similar purpose which could be used or abused; I don't Cube.
JW
2019-05-21 11:06 AM
You'd need to make sure the the pin is in a GPIO OUT PP mode, and not an AF mode.
Check GPIOA->MODER
2019-05-22 11:57 AM
Thank you for your quick response!
I think I might be missing something at the configuration files. I just created two new projects to test both options, option 1 PA9 used as UART1_TX, and option 2, PA9 used as a GPIO output PP mode.
So option 1 it's able to send bytes through UART1. But if I try to swap the PA9 configuration to standard GPIO OUT PP mode, it doesn't do anything, UART keeps sending things (I've got a loop sending DMX frame every 100 ms).
Option 2 sends the break properly. But when I try to swap the configuration to use PA9 as an UART, nothing happens. Funny thing here, I've got the following function implemented to check if the transmision was correct, and it doesn't give me any problems...
if (HAL_UART_Transmit(&huart1,(uint8_t *)DMX_test,3,0xFFFF) != HAL_OK)
{
Error_Handler();
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
}
It's like I am missing something else. Some part of the code I am not doing in between the break and the frame I want to send. And also it does happen when I finish sending the frame, I can't swap it to get the break done. I'm still learning how to work with this enviroment, it's everything new for me, so apologies in advance for my newbie mistakes...
I hope I could make myself kind of understandable. Sorry, lots of hours invested on this :(
2019-05-22 12:55 PM
This is something which is a bit more complex than clicking in Cube/CubeMX allows, so you might need to resort to register level programming.
So, get your original program, change the pin's MODE from AF to OUT
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos); // 01: General purpose output mode
and then set the pin's output level as you wish, wait, and then change back from OUT to AF
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (2 << GPIO_MODER_MODER9_Pos); // 10: Alternate function mode
There may be Cube/HAL/LL incantations for this or similar purpose which could be used or abused; I don't Cube.
JW
2019-05-29 06:23 AM
Thank you guys!
Doing
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (1 << GPIO_MODER_MODER9_Pos); // 01: General purpose output mode
and
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER9_Msk) | (2 << GPIO_MODER_MODER9_Pos); // 10: Alternate function mode
was the best and the simplest way to go. It's all working now. I'll have to get familiar with STM32 ecosystem and to skip STM32CubeMX.
Again, thank you very much, you all saved my life this time. Hopefully I can become a decent expert to help you next time :beaming_face_with_smiling_eyes:
Cheers,
Andrea