Hi,
I was just trying to communicate ADS1293 with CC2541 through SPI. The problem is that the ADS1293 is not responding as there is no signal on the MISO pin.
I wrote a value to the first register of the ADS1293 and tried reading it back but in vain.
Here is the code snippet of what I am trying to do:
void spiWriteByte(uint8 write)
{
U0CSR &= ~0x02; // Clear TX_BYTE
U0DBUF = write;
while (!(U0CSR & 0x02)); // Wait for TX_BYTE to be set
}
void spiReadByte(uint8 *read, uint8 write)
{
U0CSR &= ~0x02; // Clear TX_BYTE
U0DBUF = write;
while (!(U0CSR & 0x02)); // Wait for TX_BYTE to be set
*read = U0DBUF;
}
void TI_ADS1293_SPIWriteReg(uint8 addr, uint8 value)
{
uint8 inst;
P1_1 = 0; // /CS enable
inst = 0X7F & addr; // register address
spiWriteByte(inst); // Send register address
spiWriteByte(value); // Send data value
P1_1 = 1; // /CS disable
}
uint8 TI_ADS1293_SPIReadReg(uint8 addr)
{
uint8 pVal, inst;
P1_1 = 0; // /CS enable
inst = 0X80 | addr; // register address
// WAIT_1_3US(2); // Wait
spiWriteByte(inst); // Send lower register address
spiReadByte(&pVal, 0xFF); // Read data
P1_1 = 1; // /CS disable
return pVal;
}
void main(void)
{
CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_16M;
while (CLKCONSTA & CLKCON_OSC);
/***************************************************************************
* Setup I/O ports
*
* Port and pins used USART0 operating in SPI-mode are
* MISO (MI): P0_2
* MOSI (MO): P0_3
* SSN (SS) : P1_1
* SCK (C) : P0_5
*/
// Configure USART0 for Alternative 1 => Port P0 (PERCFG.U0CFG = 0).
PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U0CFG_ALT1;
// Give priority to USART 0 over Timer 1 for port 0 pins.
P2DIR &= P2DIR_PRIP0_USART0;
// Set pins 2, 3 and 5 as peripheral I/O and P1_1 as GPIO output.
P0SEL = (P0SEL) | BIT5 | BIT3 | BIT2;
P1DIR |= BIT1;
// Set USART to SPI mode and Master mode.
U0CSR &= ~(U0CSR_MODE | U0CSR_SLAVE);
// Set:
// - mantissa value
// - exponent value
// - clock phase to be centered on first edge of SCK period
// - negative clock polarity (SCK low when idle)
// - bit order for transfers to LSB first
U0BAUD = SPI_BAUD_M;
U0GCR = (U0GCR & ~(U0GCR_BAUD_E | U0GCR_CPOL | U0GCR_CPHA | U0GCR_ORDER))
| SPI_BAUD_E;
/***************************************************************************
* Transfer data
*/
TI_ADS1293_SPIWriteReg(0x00,0x01);
while(1)
{
TI_ADS1293_SPIReadReg(0x00);
}
}
Please help me out.