Hi, I am working on some reference C code which uses 4 wire SPI for communication with a transceiver board.
as part of the init sequence the reference code uses a GPIO to know when it is receiving packets. Thing is, I don't really understand how to implement a GPIO in arduino.. Is it simply setting a pin high and polling it until it goes low?
The code is pretty long but I am willing to post it if the question is not clear.
Any help will be highly appreciated. Thanks!
Thanks for the answers. Edit: I am setting the pin to high and it is staying there now. not sure why it pulled low before..
now I only need to understand why I'm not getting anything over SPI
Serial.print("digitalRead(SPI_DO)");
Serial.println(digitalRead(SPI_DO));*
pinMode(SPI_DO, INPUT);*
Serial.print("digitalRead(SPI_DO) after setting gpio");*
Serial.println(digitalRead(SPI_DO));*
output of this on serial monitor: digitalRead(SPI_DO) 1 digitalRead(SPI_DO) after setting gpio 1
When you set the SPI_DO pin as an OUTPUT it defaults to LOW. You then change it to an INPUT which is floating. Eventually it may float HIGH, but right away it is probably still LOW (but undefined). If you change the pinmode from INPUT to INPUT_PULLUP then you enable the internal pullup resistor and then SPI_DO will read as HIGH. Not sure why you are changing the direction of the pin in real-time though... (Might just be my lack of understanding bit-banging a SPI interface.)
I was setting the pin to high following my reference code which says to set the GPIO so I just went with it. in any case, it looks like the pin is high by default. I am waiting for it to go low to show traffic but nothing's happening. Debugging this one is going to be difficult..
Yes you seem to be totally missunderstanding how inputs and outputs work.
At any one time a pin or GPIO line can be either an input or an output. If you make it into an input then something has to drive the input to one logic state or another. You can not set an input high from your code unless you enable the internal pull up resistor. You can not set an input low from your code because ther is no internal pull down resistor.
Yeah I noticed this after I posted.. note to self: think before you post.
in any case it looks like the pin is high and is staying that way so I must have done something to offend the transceiver. I may need a scope on the SPI next to see what the issue is
Are you trying to bit bang the SPI or do you want to use the SPI hardware inside the chip.
There is an SPI libary for the arduino, look up how to use it in the referance section.
Grumpy_Mike:
Are you trying to bit bang the SPI or do you want to use the SPI hardware inside the chip.
There is an SPI libary for the arduino, look up how to use it in the referance section.
It looks like he is trying to bit bang SPI since he has already ignored a suggestion to use the SPI library, and he is trying to use pin4 for MOSI (I don't know of an Arduino that uses pin4 for that). I don't know his reasons for it, but I'm interested in watching this just in case for some odd reason I find I need a second SPI interface for something or a project's pin requirements force me to not use the hardware SPI built into the chip... Both very odd and extreme situations, but I'm taking this as a learning opportunity.
If you are bit banging then you can use any pins to do that. You can even use the pins normally used by the hardware SIP.
The last project I did required bit banging because the protocol required was not quite what the hardware SPI interface provided so I bit banged the pins instead.