2021-09-14 03:18 AM
Hello everbody!
Im new to the STM32 platfor, and i want to learn about it. For a personal project i want to make de device that tracks a crypto valuta. Just for fun.
I have a ESP8266 with the AT firmware, and I could send commands via FTDI using putty. Now I could like to use the STM32 to do that. I have the ESP connected to UART2 (PA2 and PA3).
I have setup a full speed USB port on pin PA11 and PA12 and made it a COM Port.
I found this post about AT and tried some of it. It kinda works... But I think it is waiting at those HAL Transmit and Receive line. Because the LED's stop blinking. And the com port stops working, sometime i get a respone in putty.
I was hoping someone could help me out with this problem.
Thanks!
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USB_DEVICE_Init();
MX_USART2_UART_Init();
char data[] = "AT\r\n"; //I want send: AT
char rsp[7]; //I expect the response OK: \r\nOK\r\n, six character + NUL
while (1)
{
HAL_GPIO_TogglePin(GPIOA, LED_1_Pin);
HAL_GPIO_TogglePin(GPIOA, LED_2_Pin);
HAL_UART_Transmit(&huart2, (uint8_t*)data, strlen(data) , 1000); //Send command
// CDC_Transmit_FS(data, sizeof(data)); //Show the command sent on serial monitor
memset(rsp, 0, sizeof(rsp)); // Clear buffer
HAL_UART_Receive(&huart2, (uint8_t*)rsp, strlen(rsp)-1, 1000);
CDC_Transmit_FS((uint8_t *) rsp, strlen(rsp)); //Show the response on serial monitor
HAL_Delay(1000);
}
}
2021-09-14 03:32 AM
Standard Advice:
AT commands are just about sending and receiving text.
Therefore, before getting into AT commands, make sure that you can reliably send and receive text.
Test against a terminal before adding all the unknowns of another microcontroller (eg, ESP).
Also, before involving your microcontroller, investigate the ESP's AT commands and behaviour using a terminal - so that you know what you have to expect ....
https://www.avrfreaks.net/comment/2928456#comment-2928456
The commonest mistake people make is to rely upon "blind" delays:
https://www.avrfreaks.net/comment/2306006#comment-2306006
EDIT
Also be sure to understand what CR and/or LF characters are required in your commands, and will be sent in responses:
2021-09-14 03:38 AM
why do you use both a serial connection ("UART2 (PA2 and PA3)") and a USB connection ("I have setup a full speed USB port on pin PA11 and PA12 and made it a COM Port.") ?
which one is connected to the ESP8266 ?
2021-09-14 03:52 AM
the USB port is so that I can see that it is working, like using Serial.print() in arduino. And i wanted to make a sort of setup menu via the COM port. SO PA 11/12 are full speed usb, and the ESP8266 is on UART2.
2021-09-14 03:56 AM
As stated I can send the commands via putty and a FTDI adapter.
2021-09-14 05:31 AM
I made a example with the Arduino, this will send the AT command to the esp via UART and print the output. I want o get this working on the STM. If i understand how I implement this, I can make the HTTP requests.
2021-09-14 05:50 AM
strlen(rsp) isn't doing what you want.
For responses of indeterminate length you might want to assemble a byte at a time.
2021-09-14 12:50 PM
Could you tell me a bit more about how I could make this work.
2021-09-14 03:27 PM
Look at your code:
memset(rsp, 0, sizeof(rsp)); // Clear buffer
HAL_UART_Receive(&huart2, (uint8_t*)rsp, strlen(rsp)-1, 1000);
what do you think the length of rsp will be immediately after you "clear the buffer" ... ?
2021-09-15 03:24 AM
I hook up the FTDI adpater to the UART port of the SMT and the output was good.
But reading the data is the part i cant get to work.