Skip to main content
Graduate
January 31, 2024
Solved

NUCLEO-STM32G0B1RE USART2 with CTS/RTS can NOT communicate with U-blox GSM module LARA-6004D?

  • January 31, 2024
  • 1 reply
  • 1606 views

Dear Sir,

 

I have a NUCLEO-STM32G0B1RE board. I configure USART2 with CTS and RTS try to communicate with u-blox GSM module LARA-6004D, but fails. No data received.

Is there any missing? Any comment are welcome, thanks.

hardware connection is

MCU TXD <-> GSM RXD

MCU RXD <-> GSM TXD

MCU CTS <-> GSM RTS

MCU RTS <-> GSM CTS

 

IOC config about USRAT2 are as fillows,

 

32:Mcu.IP4=USART2
65:NVIC.USART2_LPUART2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
93:PD3.Signal=USART2_CTS
96:PD4.Signal=USART2_RTS
98:PD5.GPIO_Label=USART2_TX [STLK_TX]
101:PD5.Signal=USART2_TX
103:PD6.GPIO_Label=USART2_RX [STLK_RX]
106:PD6.Signal=USART2_RX
149:ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_USART3_UART_Init-USART3-false-HAL-true
168:RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CECFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2S1Freq_Value,I2S2Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LPUART2Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,TIM15Freq_Value,TIM1Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
186:RCC.USART2Freq_Value=64000000
191:USART2.IPParameters=VirtualMode-Asynchronous
192:USART2.VirtualMode-Asynchronous=VM_ASYNC

 

 Code snippet are

 

#define RX_BUFFER_SIZE 128

typedef struct {
 uint8_t buffer[RX_BUFFER_SIZE];
 size_t head;
 size_t tail;
} RingBuffer;

UART_HandleTypeDef huart2;

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 if (huart->Instance == USART2)
 {
 /* Get the received character */
 uint8_t data = huart2.Instance->RDR;

 /* Add the data to the ring buffer */
 rx_buffer.buffer[rx_buffer.head] = data;
 rx_buffer.head = (rx_buffer.head + 1) % RX_BUFFER_SIZE;

 /* Restart the interrupt-driven reception for the next byte */
 HAL_UART_Receive_IT(&huart2, &rx_buffer.buffer[rx_buffer.head], 1);
 }
}
/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{
 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_DMA_Init();
 MX_USART2_UART_Init();
 MX_USART3_UART_Init();
 /* USER CODE BEGIN 2 */
 HAL_UART_Receive_IT(&huart2, (uint8_t*)rx_buffer.buffer, 1);
 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
	 if (i % 1000 == 0) {
		 HAL_UART_Transmit_IT(&huart2, "AT", 2);
	 }
	 i++;
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

 

 

    This topic has been closed for replies.
    Best answer by E-John

    Hi Andrew,

    After test, the conclusion is below,

    For GSM module LARA-6004D which voltage is 1.8V

    1. It needs a level-shift circuit between the STM32 and the GSM module.

    2. The 4-wire connection should be as below described, cross-over connection is not needed because MCU is DTE and GSM is DCE.

    MCU TXD <-> GSM TXD

    MCU RXD <-> GSM RXD

    MCU CTS <-> GSM CTS

    MCU RTS <-> GSM RTS

    1 reply

    Super User
    January 31, 2024

    Can you communicate with the module using a PC terminal ?

    E-JohnAuthor
    Graduate
    February 1, 2024

    Hi Andrew,

    Currently no USB-Uart with CTS/RTS dongle on my hand to do the cross-reference.

    That helps to check the GSM target side setting. I would buy one to check it. Thanks for your suggestion.