2015-12-04 03:47 AM
I'm using STM32F411RE board and trying to communicate with SIM900 over UART. I'm simply trying to send.
I put some parts of my code and would appreciate your help. I think there's some configuration issue in UART parameters.
Thanks a lot in advance.UART_HandleTypeDef huart1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
uint8_t Message[] = ''AT\r'';
uint8_t aRxBuffer[2];
int main(void)
{
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_UART_Transmit(&huart1, (uint8_t*) Message, 3, 1);
if( HAL_UART_Receive(&huart1, (uint8_t*) aRxBuffer, 2, 10) != HAL_OK)
{
while(1){
}
}
while(1)
{
}
}
void SystemClock_Config(void){
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
/* Enable HSI Oscillator and activate PLL with HSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 0x10;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
HAL_NVIC_SetPriority(SysTick_IRQn,0,0);
HAL_NVIC_SetPriority(USART1_IRQn,1,0);
}
void MX_USART1_UART_Init(void){
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart1);
}
void HAL_UART_MspInit(UART_HandleTypeDef* huart){
GPIO_InitTypeDef GPIO_InitStruct;
__USART1_CLK_ENABLE();
/**USART2 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
2015-12-04 04:33 AM
What board specifically are you using? PA9 is unusable on the STM32F4-DISCO series (407, 401C, etc)
2015-12-04 04:45 AM
I'm using Nucleo-F411RE and SIM900 works fine as I've tested it with Arduino.
UART1 Tx Rx pins for my board are PIN9, PIN10 but I think the problem is in UART1 parameters.2015-12-04 04:57 AM
Hard to say, looks Ok.
It's not as if you output anything to know if it works or not. I suspect it would return more than two characters. Perhaps you can use the VCP on USART2 PA2/PA3, and do a simple forwarding exercise in both directions USART1<->USART2 and see if you can talk to the modem via the PC Terminal. If you think the serial connection is wrong, stick a scope on it and confirm the bit timing. HSE_VALUE should reflect 8MHz, and the oscillator should be in BYPASS mode.2015-12-04 04:59 AM
Nevermind, using HSI
2015-12-07 12:05 AM
I still don't get any response from SIM900.
Read in one article that I should first send the character ''A'' to synchronize the baud rate:
AT Command Syntax
When DCE powers on with the autobauding enabled, user must first send “A� to synchronize the baud rate. It is recommended to wait 2 to 3 seconds before sending “AT� character. After receiving the “OK� response, DTE and DCE are correctly synchronized
The “AT� or “at� prefix must be set at the beginning of each Command. To terminate a Command line enter <CR> , otherwise known as carriage return or \r.
2015-12-07 05:56 AM
If you think that is the issue why don't you try that? I don't have a SIM900 hung off an STM32 to test.
If the SIM900 is on a shield, think about how that's connected to the header, and if you need to make any solder-bridges on the Nucleo board for the D0/D1 pins to have connectivity.2015-12-07 07:52 AM
Is your Modem surely connected? I have a 401RE nucleo board and it has jumpers or solder bridges under the board. Those bridges have to be in correct position before header pins and CPU pins are connected. It also makes the Nucleo board almost useless. You can make a pin toggle program to see if your serial pins are really connected correctly. Or use an oscilloscope as suggested.
By the way, do you have programming manual for your modem. It tells what you need know when using the modem. In my opinion it is very important, you don't have quess whether you need an ''A'' to start or not and so on.