This chip has a really simple SPI interface. When you shift in the
control byte, you are shifting out the status byte at the same time.
So you can do it two different ways:
You can do it with two lines of spi code, like this:
These two methods produce the same ASM code in the .LST file.
Note that 0x55 is just a representative value. You need to choose
the real value.
-----------------
I just noticed something about this chip. It claims to be an SPI interface
but it sends the LSB (bit 0) first. But the hardware SPI module in the
PIC sends and receives the MSB (bit 7) first.
There are two possible solutions to this. You can switch to using
software SPI and send the data LSB first. Or, you can use hardware
SPI as shown in the code above, but then you need to call a bit reversal
routine to convert both the transmitted data and the received data.
spi_write(reverse_bits(control_byte));
data = reverse_bits(spi_read());
I have just used the function name of 'reverse_bits' as a generic name
for any of the routines shown in the Code Library.
rdesgagn
Joined: 30 Jul 2008 Posts: 3
Posted: Wed Jul 30, 2008 4:39 pm
Thanks a lot PCM Programmer. Me too, I have noticed that the H-Bridge is sending the LSB first and I was reading it backwards so the data didn't make sense at all.
Thank you again for your help, everything is working like I want !!!
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum