Hello Texas Instruments!
I am having problems configuring a CC2510 for SPI. I would like to use the CC2510 as the master device. I am having trouble seeing a serial clock signal (SCK) on the oscilloscope on P1_5 (SCK). I am also having trouble toggling P1_6 (MOSI) with a simple toggle example in the code. Does anyone see a problem with my code regarding why I can not toggle P1_6 and why I don't see a serial clock signal on P1_5?
Is it necessary to put data on the UxDBUF, in order for a serial clock signal to appear on P1_5? The reason why I ask this question is that I have peripheral devices that require a SCK all of the time.
Note: Comment the forever for loop out when testing other parts of the program not related to toggling P1_6.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define BUFFER_SIZE 0x05
static uint8 txBufferMaster[BUFFER_SIZE];
int main(void)
{
uint8 value = 0x00;
int i;
for (i = 0; i< BUFFER_SIZE; i++)
txBufferMaster[i] = value++;
}
// Configure USART1 for Alternative 2 location => Port P1 (PERCFG.U1CFG = 1)
PERCFG |= 0x02; //PERCFG.U1CFG = 1
P1SEL |= 0xE0; //P1_7, P1_6, and P1_5 are set up as peripherals
P1SEL &= ~0x1F; //P1_4, P1_3, P1_2, P1_1, P1_0 are set up as general purpose I/O
P1DIR |= 0x1D; //P1_4 is output, P1_3 is output, P1_2 is output,
//P1_1 is input, P1_0 is output
P2SEL |= 0x40; //Give priority to USART1 over USART0 for port 1 pins
//Give priority to USART1 over Timer 3 for port 1 pins
//Give priority to Timer 1 over Timer 4
//Give priority to USART0 over Timer 1
for (;;)
volatile unsigned int i; // volatile to prevent optimization
P1_6 ^= 0x01; // Toggle P1_6 using exclusive-OR
i = 10000; // SW Delay
do i--;
while (i != 0);
/* Configure SPI1
*/
SLEEP &= ~SLEEP_OSC_PD;
while(!(SLEEP & SLEEP_XOSC_S)); //monitor XOSC stable status bit
CLKCON = 0x00; //select HS crystal oscillator & system clock source to 26 Mhz
// Set USART to SPI mode and Master mode
U1CSR &= ~0xA0;
// Set Baud Rate (SCK frequency) equal to 9596 bps for a 26 MHz system clock
// (high speed crystal oscialltor)
U1BAUD = 0x83; // BAUD_M = 131
U1GCR |= 0x08; // BAUD_E = 8
// - negative clock polarity (SCK low when idle)
// - clock phase for data centered on second edge of SCK period
// - bit order for transfers to MSB first
U1GCR |= 0x60; // CPOL = 0, CPHA = 1, ORDER = 1
/* Transfer data */
// Set SSN to active low
P1_4 = 0;
for (i = 0; i < BUFFER_SIZE; i++)
// Write byte to USART1 buffer (transmit data)
U1DBUF = txBufferMaster[i];
// Check if byte is transmitted
while(!U1TX_BYTE);
// Clear transmit byte status
U1TX_BYTE = 0;
// Set SSN to active high
P1_4 = 1;
// When finished transmitting, set green LED
P1_0 = 0; // Set SRF04EB LED1
return 0;
You will only have the clock output form the SPI master when you write a byte to the SPI bus, i.e. when the master pushes out whatever byte you have written to UxDBUF. If your slave device needs an SPI clock that runs continuously, you would need to feed UxDBUF with dummy bytes. This doesn't sound like a common SPI slave device, though so using the SPI peripheral might complicate things a bit for you. Maybe bit-banging makes things easier?
In the code, you try to toggle P1.6 (use it as a GPIO), but that pin is configured as a peripheral signal (function depending on what peripheral unit it is hooked up to internally), so you can't control it as a GPIO.
M,
Thank you for your response.
Is there an alternative to bit banging? We are anticipating polling the slave device (writing a byte to the U1DBUF register which will be moved to MOSI and receiving a response from MISO which will be moved to the U1DBUF register simultaneously) often enough to pick up any changes on the input from the slave device.
Is the only way to test if P1_6 is working as MOSI is to write a byte to U1DBUF?
Thank you in advance,
Jim
You don't have to use bit banging. My only concern was that you said that you needed to provide a clock all the time to the peripheral device. Continuously polling will most probably work, as this will activate the clock signal for each byte you're reading.
And yes - the only way to test P1.6 when configured as MOSI is to write to U1DBUF.
Did you solve you issue?
You need to change your
to something that actually sends data out using the SPI peripheral.
Regards/TA
---------------------------------------------------------------------------------------------------------Please click the Verify Answer button on this post if it answers your question.---------------------------------------------------------------------------------------------------------
Sorry,
Reposted this question as a new post.
LJT
TA12012,
I have been able to generate an output on P1_6 by writing bytes to the U1DBUF register. However, I am having problems with stepping through my code so I can examine variables and registers within IAR EW and still generate a serial clock output. Please see my most recent post including source code regarding this issue. Can you offer any suggestions?
http://e2e.ti.com/support/low_power_rf/f/155/t/188708.aspx
Thank you for your help,