Sign up ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free.

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:

  1. How SPI works in Arduino, with above API I have used in Arduino.
  2. 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.

share|improve this question
    
I think you've already seen the problem. The epaper is expecting negatibe polarity and responds in the same. But you're sending positive. The epaper can't understand you. I don't know these micros well enough to help you with specifics, sorry. To your last question, no, the is no data rate to match. SPI runs by the clock signal and as long as you don't go too fast (or very slow), it should work. –  DoxyLover Sep 17 '14 at 5:14
    
What do you mean by positive/negative polarity? Data outputs being sampled at rising/falling edge of the clock? –  venny Sep 17 '14 at 8:22
    
@venny, yes sampled in rising and falling edge –  rock_buddy Sep 17 '14 at 9:56
    
It is almost certainly incorrectly selected SPI mode. What is your SPI initialisation code on the CC2530? –  venny Sep 17 '14 at 14:08
    
@venny, I have edited my post. –  rock_buddy Sep 18 '14 at 4:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.