This post gives a little background so the scope pictures make sense. Overall, I'm having problems reading from the SPI interface. What causes the clock line to go active on the atmega168?
Here's the details:
I'm trying to get SPI working with atmega168 talking to a Nordic semiconductor RF chip (on a board from sparkfun).
I'm trying to write to the CONFIG register on the NRF, and then read it. According to the Nordic spec, To write to a register, I need to write the address of the register Or-ed with bit 5 high. Then I need to write the value to write to the register. EX:
spi_write( addr | 1<<5);
spi_write ( reg_value);
To read any register, you just send the register address to the NRF chip:
spi_write( addr );
reg_val = spi_read();
Simultaneous to any outgoing command, the NRF returns the 8-bit status register. This is followed by any further requested data. (The spi_write/read() functions pull the SlaveSelect line low and do minor other stuff to manage the transaction.)
If I understand all of this correctly, I still can't figure out how to get the data requested by the read command. In my scope pics, I'm trying to write to the CONFIG register at 0x0, and then I'm trying to read the value I've written. However, I can't get the data back.
Top line is SlaveSelect, then clock, then MOSI, then MISO. I tried reading the SPDR register to get the data (first the status register value, then the requested data) to no avail.
Any ideas what I'm doing wrong? In particular, I can't see how to get the atmega168 to drive the clock line to trigger the nrf chip to send data on the MISO line. (See Read_Write.png)
Should I expect the SCK line to go active whenever I read the atmel168 SPDR?
I couldn't upload the pictures, so here they are on my flickr page: