This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Connecting ADXL345 via SPI to EZ430-RF2500 - problems with ID reading

Other Parts Discussed in Thread: SIMPLICITI, CC2500

Hi everybody,

At first. I'm new here, sorry for possible errors.

I try to realize a wireless sensor network with the development board EZ430-RF2500. I like to detect two accerlerations with two accelerometers ADXL345 and transmitt it to an access point via cc2500 and simpliciTI. The devices are connected with SPI to the Board. The Board wiring can you see below:

P3.1----SIMO

P3.2----SOMI

P3.3----Clock

P4.3 ----Chip select not (ADXL1)

P4.4-----Chip select not (ADXL2)

At the first step i tried to read the ID of one of the slaves.

I found this example:

e2e.ti.com/.../782579 from satbir sekhon (Oct 19, 2012 ).

This code works already if I play it onto the board.

Then I tried to include this code into the application example from the development board, because I like to use the implemented RF-Interface from TI's firmware.

Then the problems began, because the code example don't work after cc2500 initialization.

If you can see below I initialize the SPI and read the slave's ID immediately after entering main (only for testing and debbuging). Here the answer from the slave is 0xE5 (11100101) and this is correct.

Then the pre-implemented part begins. Here the ez430-RF2500 tries to link with the access point via cc2500 (uses same SPI interface but here chip select is P3.0)

After this steps I Include the same code as at the beginning. Then the result of the Slave's ID is 0x72 (01110010).

I have no idea why this happens. Maybe it is necessary to reset the shift register of the USCI_B0-register - i don't know, because my experiences are quite low.

Thank you for your help.



#include "bsp.h" #include "mrfi.h" #include "nwk_types.h" #include "nwk_api.h" #include "bsp_leds.h" #include "bsp_buttons.h" #include "vlo_rand.h" #include "msp430f2274.h" /*------------------------------------------------------------------------------ * Defines *----------------------------------------------------------------------------*/ /* How many times to try a TX and miss an acknowledge before doing a scan */ #define MISSES_IN_A_ROW 2 #define ADXL1_on P4OUT &= ~BIT3; // Select the slave device #define ADXL1_off P4OUT |= BIT3; // Release the slave device #define PORT_CSB_ADXL_OUT P4OUT #define PORT_CSB_ADXL_DIR P4DIR #define wait_tm while ((UCB0STAT & UCBUSY)); // Transmission Done? #define led_delay __delay_cycles(400000); #define delay_2 __delay_cycles(10); #define delay_4 __delay_cycles(200000); /*------------------------------------------------------------------------------ * Prototypes *----------------------------------------------------------------------------*/ static void linkTo(void); void createRandomAddress(void); __interrupt void ADC10_ISR(void); __interrupt void Timer_A (void); char read_byte(char byte); void write_byte(char addr,char data); void spi_init(void); void ADXL_init(void); /*------------------------------------------------------------------------------ * Globals ------------------------------------------------------------------------------*/ static linkID_t sLinkID1 = 0; /* Temperature offset set at production */ volatile int * tempOffset = (int *)0x10F4; /* Initialize radio address location */ char * Flash_Addr = (char *)0x10F0; /* Work loop semaphores */ static volatile uint8_t sSelfMeasureSem = 0; unsigned int i,k,l=0; char x1,x0,y1,y0,z1,z0; char tick,ints,devid,dataform,power,fifo,datax,datay,dataz,bufx[60],bufy[60],bufz[60]; /*------------------------------------------------------------------------------ * Main *----------------------------------------------------------------------------*/ void main (void) { PORT_CSB_ADXL_DIR |= BIT3; //Pin8 ADXL1_off; PORT_CSB_ADXL_DIR |= BIT4; //Pin9 ADXL1_off; spi_init(); ADXL_init(); addr_t lAddr; /* Initialize board-specific hardware */ BSP_Init(); /* Check flash for previously stored address */ if(Flash_Addr[0] == 0xFF && Flash_Addr[1] == 0xFF && Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF ) { createRandomAddress(); // Create and store a new random address } /* Read out address from flash */ lAddr.addr[0] = Flash_Addr[0]; lAddr.addr[1] = Flash_Addr[1]; lAddr.addr[2] = Flash_Addr[2]; lAddr.addr[3] = Flash_Addr[3]; /* Tell network stack the device address */ // SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr); /* Initialize TimerA and oscillator */ BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 12000; // ~ 1 sec TACTL = TASSEL_1 + MC_1; // ACLK, upmode /* Keep trying to join (a side effect of successful initialization) until * successful. Toggle LEDS to indicate that joining has not occurred. */ /*while (SMPL_SUCCESS != SMPL_Init(0)) { BSP_TOGGLE_LED1(); BSP_TOGGLE_LED2(); /* Go to sleep (LPM3 with interrupts enabled) * Timer A0 interrupt will wake CPU up every second to retry initializing */ //__bis_SR_register(GIE); // LPM3 with interrupts enabled // } /* LEDs on solid to indicate successful join. */ BSP_TURN_ON_LED1(); BSP_TURN_ON_LED2(); PORT_CSB_ADXL_DIR |= BIT3; //Pin8 ADXL1_off; PORT_CSB_ADXL_DIR |= BIT4; //Pin9 ADXL1_off; spi_init(); ADXL_init(); /* Unconditional link to AP which is listening due to successful join. */ linkTo(); while(1); } static void linkTo() { uint8_t msg[3]; /* Keep trying to link... */ while (SMPL_SUCCESS != SMPL_Link(&sLinkID1)) { BSP_TOGGLE_LED1(); BSP_TOGGLE_LED2(); /* Go to sleep (LPM3 with interrupts enabled) * Timer A0 interrupt will wake CPU up every second to retry linking */ __bis_SR_register(GIE); } /* Turn off LEDs. */ BSP_TURN_OFF_LED1(); BSP_TURN_OFF_LED2(); /* Put the radio to sleep */ SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); while (1) { //__bis_SR_register(LPM3_bits); /* Go to sleep, waiting for interrupt every second to acquire data */ /* Time to measure */ if (sSelfMeasureSem) { volatile long temp; int degC, volt; int results[2]; spi_init(); ADXL_init(); /* Get temperature */ ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR; /* Allow ref voltage to settle for at least 30us (30us * 8MHz = 240 cycles) * See SLAS504D for settling time spec */ __delay_cycles(240); ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled results[0] = ADC10MEM; // Retrieve result ADC10CTL0 &= ~ENC; /* Get voltage */ ADC10CTL1 = INCH_11; // AVcc/2 ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V; __delay_cycles(240); ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled results[1] = ADC10MEM; // Retrieve result /* Stop and turn off ADC */ ADC10CTL0 &= ~ENC; ADC10CTL0 &= ~(REFON + ADC10ON); /* oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278 * the temperature is transmitted as an integer where 32.1 = 321 * hence 4230 instead of 423 */ temp = results[0]; degC = ((temp - 673) * 4230) / 1024; if( (*tempOffset) != 0xFFFF ) { degC += (*tempOffset); } /* message format, UB = upper Byte, LB = lower Byte ------------------------------- |degC LB | degC UB | volt LB | ------------------------------- 0 1 2 */ temp = results[1]; volt = (temp*25)/512; msg[0] = degC&0xFF; msg[1] = (degC>>8)&0xFF; msg[2] = volt; /* Get radio ready...awakens in idle state */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0); /* No AP acknowledgement, just send a single message to the AP */ SMPL_SendOpt(sLinkID1, msg, sizeof(msg), SMPL_TXOPTION_NONE); /* APP_AUTO_ACK */ /* Put radio back to sleep */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0); /* Done with measurement, disable measure flag */ sSelfMeasureSem = 0; } } } void createRandomAddress() { unsigned int rand, rand2; do { rand = TI_getRandomIntegerFromVLO(); // first byte can not be 0x00 of 0xFF } while( (rand & 0xFF00)==0xFF00 || (rand & 0xFF00)==0x0000 ); rand2 = TI_getRandomIntegerFromVLO(); BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz DCOCTL = CALDCO_8MHZ; BCSCTL2 |=0x42; // Set MCLK to 8 MHz and SMCLK to 4Mhz FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits FCTL1 = FWKEY + WRT; // Set WRT bit for write operation Flash_Addr[0]=(rand>>8) & 0xFF; Flash_Addr[1]=rand & 0xFF; Flash_Addr[2]=(rand2>>8) & 0xFF; Flash_Addr[3]=rand2 & 0xFF; FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit } void spi_init(void){ BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz DCOCTL = CALDCO_8MHZ; BCSCTL2 |=0x42; // Set MCLK to 8 MHz and SMCLK to 4Mhz __bis_SR_register(OSCOFF); // Turn oscilater off P3SEL |= 0xe; // P3.1,P3.2,P3.3 USCI_B0 option select P4DIR |= 0x3; // CS P4.1,Power P4.2 to be output P4OUT &= ~0x3; // SPI Definations UCB0CTL1 = UCSWRST; // **Put state machine in reset** UCB0CTL0 |= UCCKPL + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master UCB0CTL0 &= ~UC7BIT; UCB0CTL1 |= UCSSEL_2; // Select SMCLK as CLK UCB0BR0 |= 0x02; UCB0BR1 = 0; UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** delay_2; } void ADXL_init(void) { // Read thbite ID// ADXL1_on; devid = read_byte(0x80); ADXL1_off; delay_2; } char read_byte(char byte) { IFG2 &= ~UCB0TXIFG; IFG2 &= ~UCB0RXIFG; wait_tm; UCB0TXBUF = byte; // Adress to be read wait_tm; // Transmission Done? UCB0TXBUF = 0xff; // Dummy write wait_tm; return UCB0RXBUF; } void write_byte(char addr,char data) { wait_tm; IFG2 &= ~UCB0TXIFG; UCB0TXBUF = addr; // Read Dev ID wait_tm; // Transmission Done? UCB0TXBUF = data; // write wait_tm; } /*------------------------------------------------------------------------------ * ADC10 interrupt service routine *----------------------------------------------------------------------------*/ #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) } /*------------------------------------------------------------------------------ * Timer A0 interrupt service routine *----------------------------------------------------------------------------*/ #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { sSelfMeasureSem = 1; __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bit from 0(SR) }

**Attention** This is a public forum