I am using an Epaper display, which is using SPI as interface. First I tried with Arduino which is working fine. But I tried to port the same code to a different microcontroller (TI's CC2530) which is not working. Later on I understood the problem with SPI.
In Arduino, I have used SPI.begin()
, SPI.setBitOrder(MSBFIRST)
, SPI.setDataMode(SPI_MODE0)
. Same mode I have used in CC2530. But I wasn't able to get the correct response from Epaper.
When I scope the signal (oscilloscope) of MOSI, in Arduino, the signal is sending in negative polarity (falling). Epaper also responding in same fashion. When I scope in CC2530, it is giving in positive polarity (rising). But Epaper giving response in negative polarity. Which is wrong response (not expected data). There is no problem with SPI of CC2530, because I already used for TFT display, which is working fine.
unsigned char Spitransfer(unsigned char SendData)
{
unsigned char val
CS = LOW;//P0_4
val = spiwrite(SendData);
CS = HIGH;
MicroWait(15);
return val;
}
/*Some code*/
Add = GetAddressMatrix(unicode);
Spitransfer(0x03);
Spitransfer(Add>>16);
Spitransfer(Add>>8);
Spitransfer(Add);
spiBitOrder(LSB);
for(i=0;i<dtaLen;i++)
{
tempdata=Spitransfer(0x00);
matrix[i]=(tempdata); /*save dot matrix data*/
delay(5);
}
spiBitOrder(MSB);
I need to get some data in tempdata if I send dummy data to Epaper display. But tempdata is zero, which is why I can't go forward for adding pixels calculation. So I need some expert advice to solve this issue. I want to know:
- How SPI works in Arduino, with above API I have used in Arduino.
- SPI has any baudrate as UART, so slave can't understand the master signal.
In CC2530,
void SPI_Init(void)
{
PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U0CFG_ALT1; // UART 0 ALT1 : P0
// Give priority to USART 0 over Timer 1 for port 0 pins.
P2DIR &= P2DIR_PRIP0_USART0;
//SPI configuration : P0_4 - Slave Select Signal , P0_5 - SCK , P0_3 - MOSI , P0_2 - MISO
P0SEL = (P0SEL & ~BIT4) | BIT5 | BIT3 | BIT2;
P0DIR |= BIT4; //slave select is output
// 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 |= 0x05; //Mode0
}
void spiBitOrder(uint8 bit)
{
if(bit == MSB)
{
U0GCR |= 0x20;
}
else
{
U0GCR &= ~(0x20);
}
}
I have tried with Mode0 and Mode1 also.