Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Conflict between digitalRead() and SPI

$
0
0

Hi everyone,

 

I'm working on a library for CC1101. I know it exists already but I needed a different approach to simplify the use, and be directly compatible with CC430 radio core. 

 

So I started working on Arduino, and it was working well, but not perfectly. I found in a forum that could come from 5V digital inputs. Because I lost my breadboard I couldn't use a level shifter so I decided to try on my launchpad because normally my library would be directly compatible ;) the compilation runs OK but everytime try to get something from the CC1101, I got a zero. My routine looks like :

 

byte OPEN_CC1101::SpiReadReg(byte addr) 
{

digitalWrite(SS_PIN,LOW);

while(digitalRead(14));
SPI.transfer(addr | READ_SINGLE);
byte value=SPI.transfer(0);


digitalWrite(SS_PIN,HIGH);
   
   return value;
}

Nothing really amazing as you can sea ... The while(digitalRead(14)) is necessary to check that the CC1101's clock is running. And it's here where is the problem : I checked with a logic analyzer, communciation is OK but the SPI.transfer() always returns 0 even if another byte is transmitted by the CC1101. It tooks me almost a day to understand, but the problem comes from this part of digitalRead() in wiring_digital.c :

 

/*
* Clear bit in PxSEL register to select GPIO function. Other functions like analogWrite(...) 
* will set this bit so need to clear it.*/


 #if (defined(P1SEL_) || defined(P1SEL))
sel = portSel0Register(port); //get the port function select register address
*sel &= ~bit; //clear bit in pin function select register
 #endif
 #if (defined(P1SEL2_) || defined(P1SEL2))
sel = portSel2Register(port); //get the port function select register address
*sel &= ~bit; //clear bit in pin function select register
 #endif
 #if (defined(P1SEL0_) || defined(P1SEL0))
sel = portSel0Register(port); //get the port function select register address
*sel &= ~bit; //clear bit in pin function select register
 #endif
 #if (defined(P1SEL1_) || defined(P1SEL1))
sel = portSel1Register(port); //get the port function select register address
*sel &= ~bit; //clear bit in pin function select register
 #endif 

I commented it and everything works well. For now I just replaced while(digitalRead(14)) by while(READMISOPIN) with :

 

#ifdef ENERGIA
#if defined(__MSP430G2553) || defined(__MSP430G2452) // on Energia + MSP430G2553 or MSP430G2452
#define READMISOPIN P1IN&BIT6 // MISO is on P1.6
#endif
#else
#define READMISOPIN digitalRead(MISO) // on Arduino
#endif

I know that's not common to read MISO, but isn't possible to store PxSELx, modify PxSELx, do the digital reading and restore original PxSELx ?

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles