2025-01-09 06:28 AM - edited 2025-01-09 11:35 PM
Hello, Following AN4872 & UM2667 I did the following:
- Connected J15(Force DIO7 High).
- UART-Connection is like(Beside GND and Vdd):
Nucleo-Board(F401RE) <-----------------------> X-NUCLEO-BNRG2A1
PA9(UART1_Tx) <-----------------------> PA2-DIO11(UART_Rx)
PA10(UART1_Rx) <-----------------------> PA3-DIO8(UART_Tx)
- UART1 Baudrate is 115200bps
- The X-NUCLEO-BNRG2A1 was tested with the Sensor Demo Application to verify that the Preloaded firmware works and successfully initializes and runs the application.
- The Preflashed Firmware is: DTM_SPI_M2SP_Eval_Kit.
The following is a test code, USART2 is used with ST-Link for debugging.
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
// Assuming the UART handle is globally defined
uint8_t txData = 0x7F; // Data to send
uint8_t rxData = 0x00; // Buffer to store received byte
uint8_t Rx_Buff[10];
uint8_t cnt = 0;
bool Rx_Flag = False;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
HAL_StatusTypeDef status;
/* 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_USART2_UART_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
// Print_Sys();
HAL_GPIO_WritePin(BLE_Boot_DIO7_GPIO_Port, BLE_Boot_DIO7_Pin, GPIO_PIN_SET);
BLE_Reset();
HAL_Delay(2000);
// Transmit the data (0x7F)
status = HAL_UART_Transmit(Platform_UART_Handler, &txData, 1, HAL_MAX_DELAY);
while(!Rx_Flag)
{
// Receive the data
status = HAL_UART_Receive_IT(Platform_UART_Handler, &rxData, 1);
// status = HAL_UART_Receive(Platform_UART_Handler, &rxData, 1, HAL_MAX_DELAY);
if((status == HAL_OK))
{
// Data_Buff[cnt++] = rxData;
printf("Received Packet: 0x%X\r\n", rxData);
HAL_GPIO_WritePin(GPIOA, LD2_Pin, GPIO_PIN_SET);
HAL_UART_Transmit(&huart2, &rxData, cnt, HAL_MAX_DELAY);
Rx_Flag = True;
}
else
{
printf("UART Rx Error\n\r");
}
}
HAL_GPIO_WritePin(GPIOA, LD2_Pin, GPIO_PIN_RESET);
Rx_Flag = False;
HAL_GPIO_WritePin(BLE_Boot_DIO7_GPIO_Port, BLE_Boot_DIO7_Pin, GPIO_PIN_SET);
BLE_Reset();
HAL_Delay(2000);
txData = 0xF7; // BigEndian
status = HAL_UART_Transmit(Platform_UART_Handler, &txData, 1, HAL_MAX_DELAY);
while(!Rx_Flag)
{
// Receive the data
// status = HAL_UART_Receive_IT(Platform_UART_Handler, &rxData, 1);
status = HAL_UART_Receive(Platform_UART_Handler, &rxData, 1, HAL_MAX_DELAY);
if((status == HAL_OK))
{
// Data_Buff[cnt++] = rxData;
printf("Received Packet: 0x%X\r\n", rxData);
HAL_GPIO_WritePin(GPIOA, LD2_Pin, GPIO_PIN_SET);
HAL_UART_Transmit(&huart2, &rxData, cnt, HAL_MAX_DELAY);
Rx_Flag = True;
}
else
{
printf("UART Rx Error\n\r");
}
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
HAL_UART_Receive_IT(Platform_UART_Handler, &rxData, 1);
Rx_Flag = True;
}
/**
* @brief Reset BlueNRG module.
*
* None
* @retval int32_t 0
*/
int32_t BLE_Reset(void)
{
// Deselect CS PIN for BlueNRG to avoid spurious commands
HAL_GPIO_WritePin(BLE_CS_GPIO_Port, BLE_CS_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(BLE_RST_GPIO_Port, BLE_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(5);
HAL_GPIO_WritePin(BLE_RST_GPIO_Port, BLE_RST_Pin, GPIO_PIN_SET);
HAL_Delay(5);
return 0;
}
Observing the Signals on the UART-Pins (UART1_Tx and UART1_Rx) I get the following:
Big picture (Blue is STM32 UART_Tx)
1st transmitted byte 0x7F
2nd Transmited byte(after 2 seconds), I reversed the 0x7F incase the BLE reads in Bigendian.
In both cases, there is no response from the BLE Board.
Is there something wrong with my configurations? What I'm missing here?
Thank you