Go Down

Topic: [Solved] Using SPI pins with SWSerial after SD read. (Read 92 times) previous topic - next topic

Tukovich

Apr 22, 2019, 11:43 am Last Edit: Apr 22, 2019, 07:02 pm by Tukovich Reason: Solved.
Hi,

The question is, Is it possible to use MISO and MOSI pins with a software serial library (after SPI tasks are finished)?

The problem is that in my project, SPI communication is used at initialization to read configuration params from an SD card. For this, SD library is used.

Then part of this configuration data must be sent to an XBee using UART. Due to a PCB design flaw, no other pins than MISO and MOSI can be used for UART.

I tried some libraries (SoftwareSerial, NSWSerial, AltSoftSerial) to initialize a serial port in 11,12 pins but no data is received in the XBee, just rubbish when SD card is read, after that, nothing. It seems like those pins are stuck by the SD library in some way...

[Temporal solution]
I solved it by setting to '0' SPIE bit in SPCR register after SD tasks.
Code: [Select]
SPCR &= (0<<SPIE);

srnet

You have not said which Arduino you are using, which can affect which pins you can use softserial on.

An what happened when you dumped the SD card stuff (that uses SPI) and just wrote to the Xbee with software serial ?
Co-Designer of the worlds smallest (known) operational satellite, $50SAT.
http://www.50dollarsat.info/
http://www.loratracker.uk/

Tukovich

#2
Apr 22, 2019, 05:14 pm Last Edit: Apr 22, 2019, 06:34 pm by Tukovich
You have not said which Arduino you are using, which can affect which pins you can use softserial on.

An what happened when you dumped the SD card stuff (that uses SPI) and just wrote to the Xbee with software serial ?
I'm using an arduino UNO for testing. Final code will run in a bare ATMEGA328P.
If SD related code is deleted, it does work.
This is the function code I'm using by now to test communication:

Code: [Select]
void sendXbeeConfig(void){
    SoftwareSerial softSerial(11, 12); // RX, TX
    softSerial.begin(9600);

    while(true){
        softSerial.write('R');
        delay(500);

 }


If instead of software serial, arduino Tx is used, it works perfectly.

Go Up