cancel
Showing results for 
Search instead for 
Did you mean: 

AS5048 SPI Communication trouble

Thomas Carrington
Associate III
Posted on April 18, 2017 at 19:44

Hi All,

Have just moved over to the STM32 (have the Nucleo-F103RB!) device from 8bit devices, and am finding the STM32 device to be pretty cool

Currently working on a personal project, to build a robotic arm and have decided to use the AS5048A (SPI interface) as a way to measure the angular position of each joint. I've configured the STM32 to use the SPI1 interface configured with CPHA = 1, and CPOL = 0; so the clock is idle low, and the trailing edge is used to capture data, which aligns with the AS5048A datasheet. It is also setup to only send 8bits at a time, I am aware that the device requires 16bits, so I've set up the transmit to take this into account, 2 bytes are transmitted between slave selections.

When I read from the device, it seems to work.....sometimes, most of the time, I get weird data that doesn't make sense:

I am unable to clear the error flag with each package (even when reading from the 'Clear Error Flag' register; when reading data from the 'Clear Error Flag' register I get 0xC000 or 0xC001, the last one makes the least amount of sense as the data should be EVEN parity (note I have read this register multiple times, and still get this).

Even with a magnet over the chip, I seem to get sporadic data, telling me that the angle is 0/1, even when rotating the magnet in multiple directions (the magnet I have used is the one provided in the AS5048A Development board)

So, I'm a little lost as to what I've not done wrong, I've attached a copy of my code to interface to the device to this post.

The function within called 'AS5048_CompleteRead' has been able to get some good data, but as I have stated above,  it works very intermittently, and the angles I get are not consistent; one minute it says it's at angle 150deg, move it around a bit and then return, and I get a completely different number

Any help that can be provided will be most appreciated.

Regards,

  Thomas

1 ACCEPTED SOLUTION

Accepted Solutions
Thomas Carrington
Associate III
Posted on April 20, 2017 at 21:08

Jan, thanks for the thread pointer.

After reading it, I tried modifying the speed of each of the SPI pins, MISO/MOSI/SCLK, the only options I had was 2MHz, 10MHz, or 50MHz (max).

It appears that setting my SCLK to 50MHz causes it to fall apart; data read is all over the place. Bringing this to 10MHz/2MHz (my SPI clock is ~1MHz) makes everything work, data is now (very) consistent, and I was able to clear the error flag I was getting with every transmission

So I think I had the SCLK pin speed too high.....Which makes me wonder, how do I know what speed to put the pins at? As I would normally go for the highest I can get, which was wrong in this case.

View solution in original post

5 REPLIES 5
Posted on April 20, 2017 at 09:19

Set the drive ('speed') of SCK pin to high.

JW

Posted on April 20, 2017 at 13:45

Hi Jan, i don't think i understand your comment. Are you saying that i need to have the sclk pin clock speed set to the highest value (which i think is 50MHz)?

As I thought this is what I'd done

Posted on April 20, 2017 at 14:47

My tip was that this

https://community.st.com/0D50X00009Xkfq2SAB

  is the cause. It appeared in some of the erratas already as said in that thread too. I don't know if this applies to the 'F103.

JW

Thomas Carrington
Associate III
Posted on April 20, 2017 at 21:08

Jan, thanks for the thread pointer.

After reading it, I tried modifying the speed of each of the SPI pins, MISO/MOSI/SCLK, the only options I had was 2MHz, 10MHz, or 50MHz (max).

It appears that setting my SCLK to 50MHz causes it to fall apart; data read is all over the place. Bringing this to 10MHz/2MHz (my SPI clock is ~1MHz) makes everything work, data is now (very) consistent, and I was able to clear the error flag I was getting with every transmission

So I think I had the SCLK pin speed too high.....Which makes me wonder, how do I know what speed to put the pins at? As I would normally go for the highest I can get, which was wrong in this case.

Andres Cao
Associate III
Posted on April 21, 2017 at 01:14

The AS5048 datasheet has some clues. 

0690X00000606XLQAY.png

This puts the clock at fmax = 10MHz, but also check t_L. Anyway, doesn't make sense to read at more than 10kHz because that's the sampling frequency of the angle output.

I found it's best to use the minimum output speed setting that works. Otherwise you start getting reflections when you use longer cables that will make your readings erroneous. This setting is how fast the pin transitions, which of course at higher clock frequencies you'll need it to be higher. But bear in mind that if you're going to use long and uneven length cables it's best to keep it slow.