Hi everyone,
I'm using RFM69W module with Arduino pro mini and I need to drive two DC motors at 20kHz PWM on pins 9 and 10.
However as the pin D10 is already used as Slave Select (SS) by library, I have a question: is it possible to assign the SS function to, let say pin D5?
If yes, should I modify rfm69 library definitions, or could I initialize the module with SS mapped to D5 pin ?
I will really appreciate any help.
Hi,
Yup. Just change:
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
RH_RF95 rf95(RFM95_CS, RFM95_INT);
to
#define RFM95_CS 5
#define RFM95_RST 9
#define RFM95_INT 2
RH_RF95 rf95(RFM95_CS, RFM95_INT);
EDIT: I see it's a little different in the RFM69 library. Not sure if this will work, but worth a try. :D
Generally speaking, if its a master SPI then the SS# is usually just a digital output than can be moved. The SCLK, MOSI and MISO pins are often fixed (some micros allow you to move them to another set of fixed pins, but usually they are fixed). Slave SPI interfaces however usually have their SS# pins fixed too as this tristates the SCLK and potentially swaps MISO and MOSI directions, as well as putting the SPI peripheral into slave mode.
Mark.
Thanx for the prompt reply.
I'm not at home now, so couldn't test it, but I found this line in RFM69.h file :
#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on ATmega328
will it work if I simply change it to:
#define RF69_SPI_CS D5 // Set D5 pin as Slave Select (SS default pin is D10 on ATmega328)
#define RF69_SPI_CS D5 // Set D5 pin as Slave Select (SS default pin is D10 on ATmega328)
that works ONLY if I change the value in RFM69.h file and set the pin D10 to OUTPUT, so now I can use the pin D10 as PWM output for my motors.
But if add this line in sketch, BEFORE or AFTER RFM69 initialization (in setup), then radio doesn't work.
Is there is a way to assign Slave Select pin for radio from the sketch, without altering the lbrary ? (I have many other project in which I use D10 as standard SS pin)
Did you try void setCS(uint8_t newSPISlaveSelect); ?
Hi Felix,
first of all I would like to thank you for your incredible work - RFM69 library.
I added this line in the sketch (after radio initialization) : radio.setCS (8);
and it works perfectly.
Thank you very much. ;)
Great, thank you for the feedback, appreciated!
Here is a quick update.
If SS pin is assigned AFTER "radio.initialize" line, then there will be a HIGH signal on D10 pin until you set it LOW.
But if SS pin is assigned BEFORE "radio.initialize" then there is no such problem.
Yes it's best to call it before to avoid such issue.
The radio.initialize() function assumes everything is set and ready to go (including the SS pin, if not changed from default).