I'm having trouble with getting I2CD2 to function. This was working yesterday, and it is not working today. I have backed up to the code that was working yesterday, and that code no longer works today. Currently when i2cMasterTransmitTimeout is called, the pins hold steady at the top rail per the pullup resistor, and the STM32 never pulls it low. It appears that the I2C is never connected to the physical pin.
I have a program where I2CD1 has been working, and I2CD2 has been intermittent. The general flow of main.c is like this.
Code: Select all
i2cStart(&I2CD2, &i2cconfig);
i2cAcquireBus(&I2CD2);
// send it
int ret = i2cMasterTransmitTimeout(&I2CD2, I2C_SLAVE_ADDRESS, &cmd, 1, i2c_buf, len, 1000); // timeout 1000
i2cErrors = i2cGetErrors(&I2CD2);
if (ret != MSG_OK) {
for (i = 0; i < len; i++) {
i2c_buf[i] = 0; // Clear the buffer if no new data
}
i2cReleaseBus(&I2CD2);
i2cStop(&I2CD2);
In the above "ret" returns with -1 which I believe means it timed out. However "i2cErrors" returns with a 0. Per the below link, I was expecting at least the 0x20 timeout flag. However I get no flags from i2cGetErrors
https://www.playembedded.org/blog/stm32-i2c-chibios/
I think I have the DMA's setup properly. Even if I did not, then I should still be OK as expect I only preform one task at a time. There is some chance the USB terminal could be a conflict with the DMA resources. I'm not sure how to verify the USB ports DMA resources. Here's a snippet of mcuconf.h which details the I2C DMA. I do not expect to be using USART4, SPI3 or I2C3, those are detailed as FALSE. So I expect those are not being used by the USB debug serial port.
Code: Select all
/*
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 TRUE
#define STM32_I2C_USE_I2C2 TRUE
#define STM32_I2C_USE_I2C3 FALSE
#define STM32_I2C_BUSY_TIMEOUT 50
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2C_I2C1_IRQ_PRIORITY 5
#define STM32_I2C_I2C2_IRQ_PRIORITY 5
#define STM32_I2C_I2C3_IRQ_PRIORITY 5
#define STM32_I2C_I2C1_DMA_PRIORITY 3
#define STM32_I2C_I2C2_DMA_PRIORITY 3
#define STM32_I2C_I2C3_DMA_PRIORITY 3
#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
This works for I2C1, so I expect I am properly handling the 2 bytes requirement. The IO is setup with these lines. I communicate as expected on PB6 and PB7, however PF0 and PF1 stopped working and the pull up resistor indicates that I'm connected properly to those IO pins.
Code: Select all
// PMBUS/i2C - use this on the Arduino connector
// PB6/I2C1_SCL --> D1 PF1/I2C2_SCL
// PB7/I2C1_SDA --> D0 PF0/I2C2_SDA
palSetPadMode(
GPIOB,
6,
PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SCL this is needed because board.h does not seem to work properly. TODO put this in board.h
palSetPadMode(
GPIOB,
7,
PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SDA this is needed because board.h does not seem to work properly. TODO put this in board.h
palSetPadMode(
GPIOF,
1,
PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SCL this is needed because board.h does not seem to work properly. TODO put this in board.h
palSetPadMode(
GPIOF,
0,
PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUPDR_PULLUP); // SDA this is needed because board.h does not seem to work properly. TODO put this in board.h
this is with an Olimex STM32-E407 board. Attached is a copy of main.c, and my config files. If I have not provided enough information, then additional details could be obtained from those files. This is ChibiOS 20.3 and I'm using ChibiStudio on Win10. As well I have found I need to launch the GCC 7.0 launcher. If I do not then I appear to get compiler issues that cause kernel panic and unhandled exceptions.
Are there any suggestions about what could be going wrong? Am I not properly configuring the pin?