Page 1 of 1

Hardware I2C on STM32

Posted: Mon Jun 01, 2020 11:55 am
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?

Re: Hardware I2C on STM32

Posted: Mon Jun 01, 2020 1:53 pm
by LeighM
Hi,
We are working our way through supporting this for the various devices, prioritising requested parts, what processor are you looking at?

Re: Hardware I2C on STM32

Posted: Tue Jun 02, 2020 12:15 pm
by Kisen
Hi,

The processor is an STM32F411CCU6

Re: Hardware I2C on STM32

Posted: Tue Jun 02, 2020 2:28 pm
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,

Re: Hardware I2C on STM32

Posted: Wed Jun 03, 2020 9:30 am
by Kisen
Thanks Leigh,

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

Re: Hardware I2C on STM32

Posted: Wed Jun 03, 2020 11:38 am
by LeighM
Thanks.
Ben has now transferred these into the auto update system, so you can now use that to update
Leigh

Re: Hardware I2C on STM32

Posted: Sat Jun 13, 2020 9:54 pm
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??

Re: Hardware I2C on STM32

Posted: Sun Jun 14, 2020 10:42 am
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.

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 8:08 am
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?

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 8:12 am
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)

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 9:13 am
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.

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 9:43 am
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.

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 10:00 am
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?

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 10:15 am
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

Re: Hardware I2C on STM32

Posted: Mon Jun 15, 2020 11:05 am
by Kisen
Excellent, Thanks for clearing that up for me :)

Re: Hardware I2C on STM32

Posted: Tue Jun 16, 2020 8:17 am
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.