hello I write blow code with STcubemx and arm keil. I want to send a string data from MCU TO GSM module for calls. but nothing happend, when programing the chip. my question is , when send serial data with printf command , which port that command is sent (I use STM32F103C8T6 that has 3 usart)
how can I reslove this problem?
char phoneNO[]="093XXXXXX"; int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART2_UART_Init(); printf("AT"); HAL_Delay(1000); printf("ATD"); printf(phoneNO); HAL_Delay(8000); printf("ATH"); while (1) { }
.
I want to send a string data from MCU TO GSM module for calls over Usart2?
Use the HAL_UART_Transmit function (or equivalent - HAL_UART_Transmit_IT / HAL_UART_Transmit_DMA)
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
my question is , when send serial data with printf command , which port that command is sent
You need to decide and configure it to go somewhere. "Retargeting" is one way to do this. You could retarget fputc (which printf will call) to use Usart2 in which case what you wrote would work.
>>my question is , when send serial data with printf command , which port that command is sent (I use STM32F103C8T6 that has 3 usart)
I will go to whatever port you've initialized and provided fputc() functionality for.
Not done that in your code? Then it's likely to go into some big sink-hole, or generate a software interrupt or break point.
If you code things right you can have the data come out the SWO pin rather than a USART at all.
Modem also like expects a carriage return or line feed at the end of the line
yeah, I learned how to retarget uart to printf. how can I, send carriage return and line feed for that code?
printf("ATD%s\n", phoneNO); // OR \r\n
hellooo friends
my problem is solved, very thanks
for other people that have my problem, I send all code that works good on chip. (IMPORTANT OF main.c code only) softwares: cubemx 4.18, cubef1 1.4, keil uvision 5.24
#include "main.h" #include "stm32f1xx_hal.h" UART_HandleTypeDef huart2; void SystemClock_Config(void); void Error_Handler(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART2_UART_Init(); printf("AT\r"); HAL_Delay(4000); printf("AT+CMGF=1\r"); printf("AT+CMGS=09372274293\r"); printf("hellooo\x1A"); while (1) { } } PUTCHAR_PROTOTYPE /**RETARGET PRINTF TO UART2***/ { HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF); return ch; }