Incorrect value when reading GPIOB->IDR
Hello,
I have really strange behavior while reading the input port and sending the data via BLE. I have upgraded the firmware to v1.8 and I was using the BLEDataThroughput example as a base of my project. My aim is as follows
- increasing the MTU size to 200bytes
- reading the GPIOB->IDR and store it into array (output_data) when an interrupt occurs
- Repeat step 2 12500 times
- Send the output_data via BLE
I can successfully establish the data and send the values to the smartphone. However, the data becomes all zeros even if some input is actually high.
In order to expalin it clearer, I am sharing my implementations as well. Here is my interrupt handler under stm32wbxx_it.c
void EXTI3_IRQHandler(void)
{
// Clear the interrupt flag
EXTI->PR1 = GPIO_PIN_3;
GPIOC->BSRR = (uint32_t)GPIO_PIN_5;
*p_data = GPIOB->IDR;
p_data++;
counter++;
GPIOC->BRR = (uint32_t)GPIO_PIN_5;
if (counter == 12500) {
HAL_GPIO_WritePin(START_GPIO_Port, START_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(ACK_GPIO_Port, ACK_Pin, GPIO_PIN_RESET);
p_data = &output_data[0];
counter = 0;
global_count++;
UTIL_SEQ_SetTask(1 << CFG_TASK_BUTTON_ID, CFG_SCH_PRIO_0);
}
}In my bluetooth application source code, I am checking the CFG_TASK_BUTTON_ID flag as following;
typedef struct
{
SNAPSHOT_STM_Payload_t TxData;
SNAPSHOT_App_Transfer_Req_Status_t NotificationTransferReq;
SNAPSHOT_App_Flow_Status_t DtFlowStatus;
uint8_t data[25000];
} SNAPSHOT_App_Context_t;
SNAPSHOT_App_Context_t DataTransferServerContext;
extern uint16_t output_data[12500];
static uint8_t Notification_Data_Buffer[200];
uint8_t count = 0;
void SNAPSHOT_App_Init(void)
{
UTIL_SEQ_RegTask( 1<<CFG_TASK_SEND_DATA_ID, UTIL_SEQ_RFU, SendData);
UTIL_SEQ_RegTask( 1<<CFG_TASK_BUTTON_ID, UTIL_SEQ_RFU, DataReady);
/**
* Initialize data buffer
*/
DataTransferServerContext.NotificationTransferReq = SNAPSHOT_APP_TRANSFER_REQ_OFF;
DataTransferServerContext.DtFlowStatus = SNAPSHOT_APP_FLOW_ON;
memset(DataTransferServerContext.data, 0, 25000);
}
static void SendData( void )
{
tBleStatus status = BLE_STATUS_INVALID_PARAMS;
if( (DataTransferServerContext.NotificationTransferReq != SNAPSHOT_APP_TRANSFER_REQ_OFF)
&& (DataTransferServerContext.DtFlowStatus != SNAPSHOT_APP_FLOW_OFF) && count < 125)
{
/*Data Packet to send to remote*/
memcpy(Notification_Data_Buffer, &DataTransferServerContext.data[count*200], 200);
// Two lines below are for tracking how many times the transmission is handled
Notification_Data_Buffer[0] = count;
Notification_Data_Buffer[199] = global_count;
DataTransferServerContext.TxData.pPayload = Notification_Data_Buffer;
DataTransferServerContext.TxData.Length = 200;
status = SNAPSHOT_STM_App_Update_Char(DATA_TRANSFER_TX_CHAR_UUID, (uint8_t *) &DataTransferServerContext.TxData);
if (status == BLE_STATUS_INSUFFICIENT_RESOURCES) {
DataTransferServerContext.DtFlowStatus = SNAPSHOT_APP_FLOW_OFF;
} else {
count++;
UTIL_SEQ_SetTask(1 << CFG_TASK_SEND_DATA_ID, CFG_SCH_PRIO_0);
}
}
return;
}
void DataReady( void )
{
count = 0;
memcpy(DataTransferServerContext.data, (uint8_t*)&(output_data), 25000);
UTIL_SEQ_SetTask(1 << CFG_TASK_SEND_DATA_ID, CFG_SCH_PRIO_0);
return;
}I am sure that on PORTB there are some input data and I am expecting to see a value different than all zeros.
I thought maybe I am doing something wrong in BLE part and change the line *p_data = 0xFFFF; then I was able to see the all 0xFFFF in received data. So, BLE transmission seems working, however, I couldn't figure out why *p_data = GPIOB->IDR returns zeros.
I am stucking in this point and I have no idea what could be the reason. I would be really great if someone can help me.
Best regards,
Ozan