libftdi Archives

Subject: I'm still struggling with SPI.

From: John Oyler <john.oyler@xxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 26 Aug 2010 22:14:43 -0500
Here is code that compiles and does not segfault.

http://pastebin.com/DG2SqDUW

(Credit goes to the guys who do flashrom, nothing clever here is any of my 
doing.)

spi_init() seems to work as I would want. Then I send a 64 byte spi command... 
fairly certain this is working correctly. This is setting the registers for the 
sx1211 radio IC. 

Then I loop through, trying to read them back. That doesn't quite work, the 
first two reads give 0x00, then while trying to read the 3rd address, I get 
back the value of the 1st, then while trying to read the 4th I get the value 
for the 2nd, and so forth. 

The same thing happens if I try to read a single register... let's say the 
read-only signal strength register, address 0x14 (bit 6 should be set, 
according to the SX1211 docs, and the address left-shifted 1 bit, for an 
effective command of 0x68)... same thing happens. The first two times I read 
it, I'll get zero, and then I'll start seeing what look like realistic RSSI 
packets.

I don't need to read registers though... so I could care less if I solve this. 
I might want to read the RSSI, but I'll just read until I see non-zero, and use 
that. 

I do however need to read from the nss_data device, a fifo. For that, I need to 
set ADBUS4 low, and leave ADBUS3 (the typical chip select) high. Nothing I 
twiddle or tweak seems to cause that. So the past couple days I've been reading 
datasheets and application notes for the FT2232D, trying to piece together 
things as best I can. I can see some of the ftdi commands that the flashrom 
coders use, they're in AN108. Those ones even make sense.

Other things, like line 117... That seems like it's just packing a 0x00 into 
the buffer to send. Some of the debug messages I've stripped from this claim 
that that's asserting CS# (ADBUS3), but I don't see how. cs_bits is useless 
there, and pindir doesn't seem to be the answer either... it's value of 11, 
even with inverted logic, would seem to set ADBUS2 low, not 3, which is MISO. 

I've stripped this down, so the magic isn't in some other flashrom source file. 
It's not in libftdi either, which is fairly sparse source-wise itself... and 
when I follow the path the code takes, it seems to be doing low level grunt 
work, merely shipping bytes to the ftdi. 

I don't know how to use gdb, but it may be time to learn... but I'm not sure 
I'll learn much that way. I've got one of these boards soldered up with lead 
wires to ADBUS0-4, and I'll hook it up to the oscilloscope tomorrow morning 
when I'm back at work. But again... I'm not sure what that will show either, I 
already know that ADBUS3 is low, or I'd not get any SPI commands to work, even 
in the crappy way that they seem to be working. And I know with some certainty 
that ADBUS4 (which instead I want to go low) isn't... or I'd be able to read 
data out of the fifo. (Having tuned the radio to the correct config, and with 
other devices broadcasting, it's certain to have something in it).

I'm stumped. I'm either not reading the correct documentation (or maybe there 
is none). Is there anyone out there that can lend a hand?

And this doesn't even take into account that I also need to do bit-banging on 
interface B... and I can't find anything that explains how to do that. I've 
tried doing ftdi_set_interface() and then ftdi_set_bitmode(), but I'm not sure 
what's needed after that.

If anyone has any insight here, it'd be greatly appreciated.

Thanks,
John O.
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread