Skip to main content
Associate
Jul 1, 2024 8:00 AM UTC
Solved

I2C with DMA not working

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);
}

This topic has been closed for replies.
TechnBest answer
Senior III
Jul 1, 2024 10:58 AM UTC

There is option in Mx tool , open ioc file. Look for dma type , select normal. 

"If you feel a post has answered your question, please click ""Accept as Solution""."

11 replies

waclawek.jan
Super User
Jul 1, 2024 8:59 AM UTC

I2C without DMA works?

Start perhaps with bit-banged I2C to check if the connections are OK.

What are values of pullup resistors?

JW

sadeepTAAuthor
Associate
Jul 1, 2024 9:57 AM UTC

hey,

Thanks for the reply.

1. Yes. it works and gives me tepreture reading.

2. I am not using any external pullups. Am I supposed to use it like that?

 

Andrew Neil
Super User
Jul 1, 2024 10:34 AM UTC

@sadeepTA wrote:

2. I am not using any external pullups. Am I supposed to use it like that?


Pullups are fundamental to the operation of I2C.

I2C basics: https://community.st.com/t5/stm32-mcus-products/i2c-interface-with-adxl345-using-stm32f446re/m-p/658323/highlight/true#M240123 

 


@sadeepTA wrote:

My sensor is an Adafruit MCP 9600


The MCP9600 is a Microchip product: https://www.microchip.com/en-us/product/mcp9600

I presume you mean this Adafruit "breakout board" - which features the Microchip MCP9600:

AndrewNeil_0-1719829612358.png

https://learn.adafruit.com/adafruit-mcp9600-i2c-thermocouple-amplifier 

So the question becomes: does that board provide the required pullups?

The schematics are here:

https://learn.adafruit.com/adafruit-mcp9600-i2c-thermocouple-amplifier/downloads

and show that pullups are, indeed, provided on the board:

AndrewNeil_1-1719830026827.png

 

 

#Pullups #I2CPullups

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
sadeepTAAuthor
Associate
Jul 1, 2024 12:29 PM UTC

Thank you all. @Techn's idea solved my problem.