cancel
Showing results for 
Search instead for 
Did you mean: 

I2C between STM32F411 (MASTER) and STM32F103 (SLAVE)

Gary Rubin
Associate III
Posted on August 13, 2017 at 02:27

Greets All,

I am trying to set up I2C communications between a nucleo STM32F411RE board (as master) and a STM32F103C8T6 Blue Pill board (as slave). I am using cubeMX and Keil. I also want to use DMA. I want to set this up so I can test I2C Slave operations with the STM32F103, and once successful, port the master (STM32F411RE) to an RPI Zero. This way, I can isolate any issues to the RPI Python programming instead of trying to debug two systems. 

What I am looking for is example code so I can see how it is implemented. This is not a production run, but for my home use. The goal is to use the RPI Zero with the STM32F103 to add wifi enabled nodes to my home projects via web interfaces. So far, and I have googled a lot on this, I have not been able to find any code to study. 

Any links to code of working systems that use this implementation would certainly be appreciated! 

I also have a Rigol 1054z scope with (kind of) I2C decode features. 

Again, any help I can get pointing me in the right direction would be awesome.

Thank you for your time and consideration!!

#stm32f103 #stmf411 #i2c #slave #master
1 ACCEPTED SOLUTION

Accepted Solutions
john doe
Lead
Posted on August 13, 2017 at 03:37

there's board-to-board dma examples in the STM32CubeMX application's source code repository on your hard drive.

STM32Cube/Repository/STM32Cube_FW_F1_V1.6.0/Projects/STM32F103RB-Nucleo/Examples/I2C/I2C_TwoBoards_ComDMA

View solution in original post

6 REPLIES 6
john doe
Lead
Posted on August 13, 2017 at 03:37

there's board-to-board dma examples in the STM32CubeMX application's source code repository on your hard drive.

STM32Cube/Repository/STM32Cube_FW_F1_V1.6.0/Projects/STM32F103RB-Nucleo/Examples/I2C/I2C_TwoBoards_ComDMA

Gary Rubin
Associate III
Posted on August 13, 2017 at 04:18

Thank you for your reply! I am having trouble locating the resource you posted about though. I went to my windows install of cubeMX and in program files, under STMELECTRONICS, I see cubeMX, but no repository path. 

I keep my cube output path on a separate path under toolchains in my 'embedded_dev' folder. I checked there too.

Am I missing something?

Sorry to be so needy. I'm not an engineer, software or otherwise. But I do write code that runs in linux, windows, and on many embedded platforms. 

EDIT: I found reference to '

I2C_TwoBoards_ComDMA

' here...

C:\embedded_dev\Keil_v5\ARM\PACK\Keil\STM32F4xx_DFP\2.11.0\Projects\STM32F429I-Discovery\Examples\I2C and several other places. Is this where I need to look?

Posted on August 13, 2017 at 04:39

Its a good start! From the CubeMX application's HELP menu, you can install repositories for other chip families. 'Install New Libraries'  I'm no engineer either, im just a bit-fumbling amateur.

Posted on August 13, 2017 at 05:00

'

a bit-fumbling amateur' is good enough for me. Actually close to what I am. Thank you sir!

Gary Rubin
Associate III
Posted on August 13, 2017 at 16:22

It looks like I got what I needed and it was right under my nose. Thank you John Doe for the push in the right direction! The examples are not for my board (as master) but it gives me what I needed to see. This also unlocked a world of other information for me too. THANK YOU!

Gary Rubin
Associate III
Posted on September 11, 2017 at 01:59

As it turned out, this solution got me to where I needed to be, but it was not at ALL easy. I had to port the example to something more consistent with what CubeMX generates. The example did not follow that structure at all. Then, as it turned out, the example was static to the example's goal, meaning that there was no consideration made for other tasks. So using it to facilitate I2C communications froze my other tasks, like constant updating of a OLED display using SPI. At first I thought the I2C peripheral process and associated interrupts were conflicting with the SPI communication with the SSD1306 controller. This seems not to be the case at all however, and I am working now on a solution that allows interrupt driven servicing of I2C communications while still allowing a main program loop to go about its business.

Another thing to note... although there were examples available using the solution here that showed programming that supports I2C, it was not available for my MCU. Actually, only the example that used DMA, for the STM32F411E-Discovery was viable. Being a huge fan of discovery and nucleo boards, I decided to buy 2 STM32F411E-DISCO boards so I could hook them up to each other to fully test the example and study the code. Then I ported the receiver slave code to my target, the STM32F103C8T6 and it worked! Later comes porting the master to linux python on a RPI Zero Wifi under Debian Linux. The discovery boards I bought, along with all the nucleo and other boards I acquired will serve their purpose in some design or bench testing function I am sure. 

So now I am working on interrupt driven I2C servicing. I think I have enough to go on with the examples to make that happen. Then I will have my in-between board between my RPI Zero and the project MCU's, etc. When that is done, I will post that here so others trying to do the same thing will have my breadcrumbs to follow and have success.

Thanks again for all the help and advice! I would not be where I am now without it. That is certain!!