Following considerable frustration fruitlessly attempting to get I2C working on ARM (STM32F411) to simply address an AS5600 hall position sensor in hardware mode, whilst working perfectly in software mode, I happened to chance upon mention that I2C will only operate in transaction mode on ARM.
To cut a long story short, I'm confused at how to implement the same working approach with I2C transactions, not entirely helped by limited explanations of what's going on 'under the hood' for reads and writes in transaction mode.
In summary, I'm attempting to simply read the status register 0x0b of an AS5600 rotary hall sensor. Unfortunately, high-speed I2C in software mode is a non-starter, but would be good to have a working understanding of Transaction Mode in any case.
From the basic example project 'I2C Transaction Example', Transaction_Initialise is perfectly clear, but I'm trying to drill down to the precise I2C Transaction sequence required to perform the following - exemplified as simple I2C transactions that work in software mode. I've made various attempts without progress, so time to ask for help.
1. START
2. TRANSMIT BYTE '0b01101100' (chip 7-bit I2C address plus trailing Write bit)
3. TRANSMIT BYTE 0x0b (address of register to read)
4. RESTART
5. TRANSMIT BYTE '0b01101101' (chip 7-bit I2C address plus trailing Read bit)
6. RECEIVE BYTE (data from register address 0x0b)
7. STOP
This is the first time I've been forced to use necessary I2C 'transactions' on ARM, so clarification of the above will carry over to future projects.
Many thanks,
Brendan
Reading AS5600 registers with ARM using I2C Transactions
-
Brendan
- Posts: 72
- http://meble-kuchenne.info.pl
- Joined: Tue Dec 08, 2020 2:12 pm
- Has thanked: 59 times
- Been thanked: 16 times
-
mnfisher
- Valued Contributor
- Posts: 1763
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 148 times
- Been thanked: 831 times
Re: Reading AS5600 registers with ARM using I2C Transactions
Hi Brendan,
That should be something like:
TransactionInitialise(addr) // addr is 7 bit address of device
Then:
Note that Write does addr << 1 (and Read does (addr << 1) | 1) - and this is sent before contents of buf for Write (or prior to the Read)
TransactionWrite takes the number of bytes to send - and optionally set bit 15 to do restart rather than STOP before the read.
Martin
That should be something like:
TransactionInitialise(addr) // addr is 7 bit address of device
Then:
Code: Select all
.buf[0] = 0x0b // Register to read buf is an array of bytes (one or more!)
TransactionWrite(.buf, 0x8001) // Writes addr (set in initialise) and 0x0b - restart rather than stop...
TransactionRead(.buf, number_of_bytes) // Or use a different buffer to read to?
TransactionWrite takes the number of bytes to send - and optionally set bit 15 to do restart rather than STOP before the read.
Martin
Re: Reading AS5600 registers with ARM using I2C Transactions
Thank you so much Martin for your interest and early reply.
I really do appreciate your time and support, enabling me to continue a challenging multi-axis automata project in the time remaining before returning to work.
Best regards,
Brendan
I really do appreciate your time and support, enabling me to continue a challenging multi-axis automata project in the time remaining before returning to work.
Best regards,
Brendan
-
LeighM
- Valued Contributor
- Posts: 524
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 91 times
- Been thanked: 280 times
Re: Reading AS5600 registers with ARM using I2C Transactions
Just to add to Martin's note...
If that 0x8001 restart doesn't work on this device,
I2C restart is the same as stop/start in functionality, just a bit quicker.
So a write transaction of 1 byte with the register address, followed by a read one byte transaction should work equally well.
If that 0x8001 restart doesn't work on this device,
I2C restart is the same as stop/start in functionality, just a bit quicker.
So a write transaction of 1 byte with the register address, followed by a read one byte transaction should work equally well.
Re: Reading AS5600 registers with ARM using I2C Transactions
Thank you Leigh. Again, entirely appreciated.
Still having issues, though I'm sure I'll get there eventually with further experimentation, with success followed by the usual epiphany
All the best,
Brendan
Still having issues, though I'm sure I'll get there eventually with further experimentation, with success followed by the usual epiphany
All the best,
Brendan
Re: Reading AS5600 registers with ARM using I2C Transactions
Hi Martin.
Thank you again, though happy to report that AS5600 I2C transactions are now working.
Following your suggestions, I just needed to send the TransactionWrite and TransactionRead in suggested order, but without inhibiting the Stop/Start by not setting bit 15 (per Leigh's suggestion).
I provide below the working flow pictorial, though happy to create a dedicated example project if you think it may be of some help.
Once again, thank you Martin and Leigh for your indispensable support.
Best regards,
Brendan
Thank you again, though happy to report that AS5600 I2C transactions are now working.
Following your suggestions, I just needed to send the TransactionWrite and TransactionRead in suggested order, but without inhibiting the Stop/Start by not setting bit 15 (per Leigh's suggestion).
I provide below the working flow pictorial, though happy to create a dedicated example project if you think it may be of some help.
Once again, thank you Martin and Leigh for your indispensable support.
Best regards,
Brendan