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

QUESTION on using SoftSPI #7

Closed
mjs513 opened this issue Sep 25, 2017 · 4 comments
Closed

QUESTION on using SoftSPI #7

mjs513 opened this issue Sep 25, 2017 · 4 comments

Comments

@mjs513
Copy link

mjs513 commented Sep 25, 2017

In looking through the code I noticed you are not setting a CS pin anyway. Am I assuming it is in effect always selected for that group of pins? Also if there is no CS function then am I assuming correctly you can only have I device attached for the set of pins selected?

Another question is I am trying to attach a 9250 to a new board and use the lib to read say the whoami register. Do I use the send/receive combo or use transfer (the first to send the addr and the second to read the data).

Thanks
Mike

@greiman
Copy link
Owner

greiman commented Sep 25, 2017

You must handle CS just like hardware SPI. You can have multiple devices with different CS pins. They must all use the same SPI mode.

You only need transfer(). It works like hardware transfer().

  spi.send(data);
  // same as this transfer call but maybe a bit faster.
  spi.transfer(data);
  data = spi.receive();
  // same as this transfer call but maybe a bit faster.
  data = spi.transfer(0xff);

@mjs513
Copy link
Author

mjs513 commented Sep 25, 2017

Hi. Thanks for getting back to me. Did what you said this morning with the transfers just like normal SPI and it worked. Got confused when looking at the example (and working late at night). Now I am trying to get it work from within a 9250 library.

I declared the SoftSPI as spi in the main sketch but now getting spi not defined errors from within the library. How do I get it work? Any ideas. Here's the exact error


`C:\Users\CyberPalin\Documents\Arduino\libraries\MPU9250SPI\mpu9250_spi.cpp: In member function 'unsigned int mpu9250_spi::WriteReg(uint8_t, uint8_t)':

C:\Users\CyberPalin\Documents\Arduino\libraries\MPU9250SPI\mpu9250_spi.cpp:24:3: error: 'spi' was not declared in this scope

   spi.transfer(WriteAddr);`

Thanks
Mike

@greiman
Copy link
Owner

greiman commented Sep 25, 2017

Modifying a library to work with SoftSPI may not be easy. I can't guess about the structure of your 9250 library.

I really don't have time to help you convert a library from hardware SPI to SoftSPI.

A first step is to add an extern statement to the library.

If spi is define in your sketch like this:

#include "DigitalIO.h"
SoftSPI<7, 8, 9, 0> spi;

You will need something like this to define spi in the library.

#include "DigitalIO.h"
extern SoftSPI<7, 8, 9, 0> spi;

Good luck, sorry I don't have time to help more.

@mjs513
Copy link
Author

mjs513 commented Sep 25, 2017

Bill appreciate any help. Really wasn't looking for you to convert the library, I got that one. Just didn't know how to do the referencing. Think I can go from there.

Thanks again
Mike

UPDATE: Just to let you know I added the extern statement to the library (already did the other part of the conversion :) ) and it work perfectly.
Thanks again.

@mjs513 mjs513 closed this as completed Sep 25, 2017
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

2 participants