2024-07-01 01:00 AM
Hi,
I'm somewhat new to STM32. I need to use DMA to collect data from a tempreture sensor over I2C.
My sensor is an Adafruit MCP 9600 and I'm using a Nucleo F446RE board. Following is the code I use. Can someone help as I've been stuck here for days without knowing what to do.
uint8_t TMP_ADDR = 0x65 << 1;
uint8_t TMP_REG = 0x00;
uint8_t TempReading[100];
void MCP9600_ReadTemperatureDMA(void)
{
TempReading[0] = TMP_REG;
if (HAL_I2C_Master_Transmit(&hi2c1, TMP_ADDR, TempReading, 1, HAL_MAX_DELAY) == HAL_OK) {
if (HAL_I2C_Master_Receive_DMA(&hi2c1, TMP_ADDR, TempReading, sizeof(TempReading)) == HAL_OK) {
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
}
}
}
// I2C DMA Transfer Complete Callback
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
{
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
}
Solved! Go to Solution.
2024-07-01 05:28 AM
Hey,
Thank you so much for this.
2024-07-01 05:29 AM
Thank you all. @Techn's idea solved my problem.