SPI Slave SX28 w/ BS2 master Questions
![Capt. Quirk](https://forums.parallax.com/uploads/userpics/9JPOS4RYYPQ0/nAZVBWA800QOI.jpg)
·I am trying to initially transfer 2 Words, per shiftout from a BS2 to be used as variables·within the SX 28. A total of 4 BS2 SHIFTOUT commands, transferring 2 words per command.·My goal is a total of 8 words per program cycle. Also it only needs to be a slave, no reason for the sx to return info. The program was written be Bean HERE
I am confused about the code in the Main:, section that is accessing the data buffer. I have tried changing the program to access the·spiData(array) to produce two Word variables and I am not doing so well. After that I need to be able to access·the remaining·12 bytes for the remaining 6·word data variables.
Does·spiData(array)·get incremented after·each·interrupt?. It looks like the sub SPIRecvCount would reset the data buffer before the next SHIFTOUT cycle from the BS2.
Another question, that so far hasn't effected the demo, is, what is the clk pin doing?, is it not used?
The BS2 program is·commented into the top of the program.
I am confused about the code in the Main:, section that is accessing the data buffer. I have tried changing the program to access the·spiData(array) to produce two Word variables and I am not doing so well. After that I need to be able to access·the remaining·12 bytes for the remaining 6·word data variables.
Does·spiData(array)·get incremented after·each·interrupt?. It looks like the sub SPIRecvCount would reset the data buffer before the next SHIFTOUT cycle from the BS2.
Another question, that so far hasn't effected the demo, is, what is the clk pin doing?, is it not used?
The BS2 program is·commented into the top of the program.
Comments
The clk pin is an input and receives the clock pulse from the SHIFTIN/SHIFTOUT commands from the Stamp.
And it triggers the interrupt state machine to sample the data pin.
I am trying to initially transfer 2 Words, per shiftout from a BS2 to be used as variables within the SX 28. A total of 4 BS2 SHIFTOUT commands, transferring 2 words per command. My goal is a total of 8 words per program cycle. Also it only needs to be a slave, no reason for the sx to return info. The program was written be Bean HERE
I am confused about the code in the Main:, section that is accessing the data buffer.
-- it waits for X bytes to go into the array; that's what spicnt is for. What bean does in his sample is set the count for 4 (wait for four bytes), then he takes each two byte chunk and moves it into a word. You could just easily set spicnt for 4 byte, then access the two words at once from the buffer., e.g.
Does spiData(array) get incremented after each interrupt?.
- No, there's a state machine in the ISR, so the array pointer for the next byte is only incremented after 8 bits have been received for the current byte.
It looks like the sub SPIRecvCount would reset the data buffer before the next SHIFTOUT cycle from the BS2.
- No, it waits for the buffer to have X bytes in it
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
It looks like I could shiftout 8 words of data (4 shifts, 2 words at a time) from the BS2·to the SX and then retrieve all the data, at one time within the main program routine through the spiData array? So long as it's array pointer·is always reset after the retrieval? Or would that cause an issue, if the SX's buffer is full and the·BS2 requests another shiftout·to the SX.
CS seems to cause the interrupt and is reset at the bottom of the interrupt. In the BS2 program Bean put a Pulsin that pulls CS low for 100us and creates an interrupt code.·The clock, is also set to cause an interrupt, but I didn't see any lines of code that referenced that pin or bit or reset, after the decleration. I thought SPI required the clock function. Am I just not seeing it?
Bill
Post Edited (Capt. Quirk) : 5/7/2009 11:49:18 PM GMT
The clk pin causes an interrupt because it's defined as part of the pin declaration (must be a port b pin, btw). The CS also causes an interrupt. In either case it's the state machine in the ISR that decides "what to do"-- if a byte is not in progress and the buffer is empty, and CS goes low, then it sets up for receiving bytes. If byte is in progress and clk goes high, it grabs the data bit. If a byte is done and cs has not gone high, it preps for the next byte.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php