I2C with DMA not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 1: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.
- Labels:
-
DMA
-
I2C
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:58 AM
There is option in Mx tool , open ioc file. Look for dma type , select normal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 1:59 AM
I2C without DMA works?
Start perhaps with bit-banged I2C to check if the connections are OK.
What are values of pullup resistors?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 2:57 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:15 AM
I2C typically expects them. Internal pull-ups on STM32 pretty weak and slow, especially if presented a relatively large capacitive load..
Get a scope or logic analyzer on the signals to better understand what's happening.
You work with people with related competencies? Manager, supervisor, colleagues?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:16 AM
Can you try with Normal dma setting. You are triggering dma every time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:18 AM
DMA and IT routines return immediately, watch for error returns and longevity of data contexts/scope passed to routines. ie not auto/local to calling subroutine.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:20 AM
Thank you for the answer. I will try with external pullups.
No, I'm learning this on my own.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:21 AM
Thanks for the reply. But can you please explain it a little bit more?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:34 AM - edited ‎2024-07-05 6:57 AM
@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.
@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:
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:
#Pullups #I2CPullups
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-07-01 3:58 AM
There is option in Mx tool , open ioc file. Look for dma type , select normal.
