Hardware I2C on STM32

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Hardware I2C on STM32

Post by Kisen »

Hi,

I have recently purchased flowcode and there doesnt seem to be an option for hardware I2C on the STM32.

Software I2C isnt fast enough for my application.

Is this something you will be adding soon or is it just being left out indefinitely?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

Hi,
We are working our way through supporting this for the various devices, prioritising requested parts, what processor are you looking at?

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Hi,

The processor is an STM32F411CCU6

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

Hi,

Attached are two updated files to give you hardware I2C support on 32F411CC

STARM_CAL_I2C.c
to replace the file found in ...
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\STARM

32F411CC.fcdx
to replace the file found in ...
C:\ProgramData\MatrixTSL\FlowcodeV8\FCD\ARM

Your Flowcode update feature will flag these as non-genuine until we get these changes into the update system, which can take a while in the current circumstances.

Please note that the hardware I2C on these devices is only supported in transaction mode of the Flowcode I2C CAL component.
This component can be found under the Creation toolbar icon.
Use Transaction_Initialise, Transaction_Read and Transaction_Write functions.

Hope that gets you started.
Regards,
Attachments
32F411CC.fcdx
(45.88 KiB) Downloaded 124 times
STARM_CAL_I2C.c
(22.08 KiB) Downloaded 124 times

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Thanks Leigh,

I will try these out and come back to you if i have any issues.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

Thanks.
Ben has now transferred these into the auto update system, so you can now use that to update
Leigh

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Can you tell me the purpose of the transaction initialise macro please.

I am unsure if this is a START command or an Initialisation for the I2C bus. Why do i need to put an address in??

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

It is an Initialisation of the I2C bus and driver.
The entered address is then used for all subsequent read and write transactions on that component. The read and write functions just take a data buffer.
Hope that helps.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Thanks Leigh.

Makes sense, well kind of.

So i do init with what address? The base address?
Then when doing a transaction how should i specify read and writes?

As i understand an I2C read for say.....2 bytes.

START,
SEND ADDRESS WRITE ADDRESS
SEND REGISTER TO READ FROM
SEND READ ADDRESS
READ DATA
READ DATA
STOP

The way i understand it with these transactions is

INIT - USING ADDRESS (BASE??)
SEND ADDRESS WRITE AND DATA IN A BUFFER (buffer, nbytes)
READ ADDRESS AND GET DATA INTO BUFFER (buffer, nbytes)
DEINIT TO CLOSE THE BUS.

Is this correct?

I have 1 device that specifically requires a RESTART. Will a "DEINIT" - "INIT" have the desired effect?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

Could you post the datasheet for the device, or a link to it?
Thanks

The usual sequence is:

Initialise communications driver, this is done once at the start of the application
device address can usually be configured with hardware address inputs

Code: Select all

Transaction_Initialise (device address)  
Setup data buffer with data that needs to be written to the device, e.g. an internal read start address
buffer[0] = internal register address

Code: Select all

Transaction_Write(buffer, 1)
Read the required number of data bytes (n) from the device

Code: Select all

Transaction_Read(buffer, n)

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Thanks for that Leigh,

Im still getting a bit hung up on the INIT at the beginning of the application.

My hardware has 7 I2C devices on it. So putting an address into the INIT to activate the bus is difficult, especially since you said previously that this address is then used for subsequent read/writes.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

Ah, right.
You will need 7 instances of the CAL I2C component, one for each device.
Then initialise all 7, then call the read/write functions of each one depending upon which device you want to access.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Not what i was expecting, but OK. I can do that.

I cant see an answer as to what address i should enter for the address.

Is it the base address, read address or write address?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

you need the 7 bit I2C device address, it will be unique to each device on the bus
i.e. ignore the read/write bit

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: Hardware I2C on STM32

Post by Kisen »

Excellent, Thanks for clearing that up for me :)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Hardware I2C on STM32

Post by LeighM »

btw:
You do also have the option of using one I2C CAL component,
Initialise to one address, write, read etc., then UnInit,
then repeat for a different device address.

Post Reply