Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI_MODE #14

Open
scargill opened this issue Aug 3, 2016 · 5 comments
Open

SPI_MODE #14

scargill opened this issue Aug 3, 2016 · 5 comments

Comments

@scargill
Copy link

scargill commented Aug 3, 2016

I wonder if you or anyone else can help.

I'm trying to get this code working with a simple example of an Arduino slave...
https://forum.arduino.cc/index.php?topic=184527.0

I have the SLAVE demo running - as far as I can tell it should at least toggle the light on and off when it gets a byte with 1.

So I tried - I am SURE the wiring is right - the light on the Arduino is on and the serial says it is ready...

But nothing... when I tried

spi_init(1); // HSPI mode
spi_tx8(1,arg1);

with various values for arg1 including of course - 1..

Then I noted you have a function called spi_mode - which does not seem to be used in any of your examples and is not called in your c code.. I added that into the init and tried all 4 variations of args 2 and 3 in spi_mode....

Am I missing something? any pointers?

Pete.

@kanflo
Copy link

kanflo commented Aug 3, 2016

Hi @scargill. Assuming you do have no logic analyzer, have you tried driving an LED with the MISO, MOSI, SCK and CS pins? I guess a while(1) spi_tx8(...); would yield some flutter. You could of course swap the ESP for an AVR based Arduino to rule out any ESP/SPI related issues.

@scargill
Copy link
Author

scargill commented Aug 3, 2016

I only have the one nano sadly... I'm looking at the code for the Arduino - and it seems to be receiving a byte and sending one as well. Does that means I should be doing this? I'm getting some debug feedback from the Arduino but it is not receiving the "1" I'm trying to send.. So I looked at the ESP code and it appears one can send and receive at the same time - I tried that - no better.

This is my attempt at sending and receiving 8 bits.. really not sure about that spi_mode command however. Look good/bad?

spi_init(1); // HSPI mode
spi_mode(1,0,0);
//spi_rx8(1);
//spi_tx8(1,arg1);
spi_transaction(1,0,0,0,0,8,arg1,8,0);
ok();

@MetalPhreak
Copy link
Owner

I ran into an issue with a particular SPI device that expected the chip select (slave select) pin to be opposite to what the ESP8266 does for active. (ie active low instead of active high). There’s no way to reconfigure this on the ESP8266 that I’m aware of which is odd because it’s pretty common in most microcontrollers. Absolute best way to debug SPI on anything is to use a logic analyser. The cheap $10 clones are good enough with the open source sigrok (or use the official salae logic app if it’s “compatible”). Just to make sure the ESP8266 is actually putting out what you expect. I’ve also used a Rigol scope heaps with SPI decode enabled.

On 3 Aug 2016, at 8:02 AM, Peter Scargill [email protected] wrote:

I wonder if you or anyone else can help.

I'm trying to get this code working with a simple example of an Arduino slave...
https://forum.arduino.cc/index.php?topic=184527.0 https://forum.arduino.cc/index.php?topic=184527.0
I have the SLAVE demo running - as far as I can tell it should at least toggle the light on and off when it gets a byte with 1.

So I tried - I am SURE the wiring is right - the light on the Arduino is on and the serial says it is ready...

But nothing... when I tried

spi_init(1); // HSPI mode
spi_tx8(1,arg1);

with various values for arg1 including of course - 1..

Then I noted you have a function called spi_mode - which does not seem to be used in any of your examples and is not called in your c code.. I added that into the init and tried all 4 variations of args 2 and 3 in spi_mode....

Am I missing something? any pointers?

Pete.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #14, or mute the thread https://github.com/notifications/unsubscribe-auth/AHZnafTsT7Acn7pBei-r25oIQDRp1NQLks5qb9qogaJpZM4JbK9T.

@kanflo
Copy link

kanflo commented Aug 3, 2016

The following should work:

spi_init(1); // HSPI mode
spi_tx8(1, arg1);
ch = spi_rx8(1);

(I swapped the calls to rx8 and tx8). As the Arduino seems to receive the byte the CS pin is correct, check the MISO connection. As @MetalPhreak wrote, you should definitely get a logic analyzer.

@scargill
Copy link
Author

scargill commented Aug 3, 2016

I have that transmit and receive - and what I'm sending out on the ESP seems right - but what comes back is rubbish - I realise the ESP can set which edge the clock runs on - and whether the clock is high normally - I'm not sure what the Arduino is expecting....

So I'm sending spi_transaction(1,8,1,0,0,0,0,8,0);

The first byte out is 1 - I'm sending no data at the end there - just receiving 8 bytes... but I'm NOT getting what the Arduino thinks it is sending back. Can someone confirm how the Arduino is expecting things to work - I'm assuming ENABLE normally high, active low, CLOCK normally high trigger on rising edge
??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants