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.

SPI in CC25xx

Other Parts Discussed in Thread: CC2530

I am using SPI communication using CC2530/41. I have one query

 byte spi_write(uint8 data)

{

       U0DBUF = data;

         /*Condition*/

          return U0DBUF;

}

1. The data in U0DBUF will transfer from MSB or LSB?

2)How can change the direction of shifting in and out in SPI Bus(MSB or LSB).

3)Is it possible to have 5k buffer in CC2541/30. Because it has only 4k RAM. I mean to ask is, is there any possible to store/access that buffer from flash

  • Can any one respond this.

  • 1&2, The default is LSB. You can change bit 5 of register U0GCR to 1 to make it MSB. Please refer ti  swru191.

    3. It is hard to have 5K buffer in CC254x/CC253x.

  • I have created the SPI driver according to User manual. But it is not working for me. Here the files0535.spi.rar.

    My piece of code is

    int main()
    {
    SPI_Init();
    spiBitOrder(0);//LSB First
    for(i=0; i<16; i++)
    {
    GetData[i] = spiwrite(0x00);
    }

    spiBitOrder(1);//MSB First
    P0SEL = 0x2C;//Make Port 0, pin 0,1,4,6,7 as Gpio
    P0DIR = 0xD3;//as Output
    P1SEL = 0xF0;// Make Port 1, pin 0,1,2,3 as Gpio
    P1SEL = 0x0F;// as output
    P2SEL = 0xFE; // Make Port2_0 as Gpio
    P2SEL = 0x01; // as input

    if(P2_0 == 1)
    {
    rsp = spiwrite(0xF0);
    }
    if(rsp = 0x01)
    {
    -------
    }

    .............
    .............

    Did i done any mistake. I could able to read the response  from Slave

  • Why do you sen P0.2 and P0.3 to GPIO after SPI_Init? You shouldn't do this.

  • I want to use those pin as gpio. After SPI_Init I am making gpio which is marked ad yellow. In that I am not making spi pins as gpio. Then what is the way to use those pins.
  • I suggest you make SPI work first otherwise you won't know what causes your problem.

  • Yes. It is working. But I don't know, it is behaving correctly. I want to use Epaper Display(Pervasive Display). I used Aurdunio board earlier working on CC2530. Which is working is fine. When I check the signal,(Scope with Oscilloscope), of Aurdunio MOSI Pin,which is configured as Mode0. The signal is sending with negative polarity of Clock(Falling). But When I try to send same command from CC2530. It is misbehaving, It is sending in positive polarity

    Aurdunio     - ----     --------     ---------     ----------

                               ----          -----         ----

     

    CC2530                           ---               ---

                         ----------------        ----------     ---------

    I suspect it is giving wrong signal, which is why epaper doesn't understand.

     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 in matrixdata[i]*/
            delay(5);
        }
     
    spiBitOrder(MSB);

    This code is staring point. I am supposed to get some values on tempdata. But I am not getting any thing from epaper. As you suggested, I removed other GPIO settings which is required for epaper display. After PowerOn of COG. But before that I need to have matrix. This itself I am not able to get it. Is my setting of SPI is correct.

              Is there any thing of Conflict in Baud rate like in UART. Can you help me to fix this SPI issue.

  • You can try to set bit 7 and bit 6 on U0GCR to change SPI clock polarity and phase.

  • I tried to change.. But it is giving same. I tried with different hardware also.

    1.Is my spiBitOrder() is correct for MSB and LSB. 

    2.What i need to set in U0BAUD for SPI. I have set as 0. 

  • 1. Your spiBitOrder should be revised as the followings:

    void spiBitOrder(uint8 bit)
    {
        if(bit == MSB)
        {
            U0GCR |= 0x10;
        }
        else
        {
            U0GCR &= ~0x10;
        }
    }

    2. If you want to use SPI@1M, you can set

      U0GCR |= 0x05;
      U0BAUD = 0;

    All these settings can be found in  swru191.

  • Thanks Mr.Chen for Supporting me. I think for MSB, U0GCR |= 0x20. I have changed in my code. But still that mode issue is exist. I have tried all modes. When i used to see in oscilloscope. It is showing same response. It is sending in rising edge, 6082.Signal.doc. Which is no where relate, what aurdunio is sending. I have done all the possibilities, What can i do further. I request to guide me

            All i also noticed that,the loop is taking too much time. Where aurduino is very less less time. 

     for(i=0;i<dtaLen;i++)
        {
           matrix[i]=Spitransfer(0x00);
        }

  • It looks weird in spiwrite. Try to revise yours to the followings:

    byte spiwrite(uint8 c)
    {
         
             U0CSR &= ~(0x04 | 0x02);
             U0DBUF = SendData;
            
             while( !(U0CSR & 0x02) );
        
          return U0DBUF
    }

  • Hi Chen,

          I am having problem in SPI. my Code is hanging in   while( !(U0CSR & 0x02) );. After some iteration. I unable to find the reason.

  • Do you mean your SPI would work a while then stop? Can you show me your current source code using SPI?

  • I tried without Zstack also. I faced same problem.

    #include "Epaper.h"
    #include "SPI.h"
    #include <string.h>
    
    /*Channel Select and for 2.7"*/
    static unsigned char channel_select[] = {0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x00};
    static unsigned char gate_source[] = {0x72, 0x03};
    
    unsigned char epaper_image[792];
    unsigned char tMatrix[32];
    
    void MicroWait( uint16 timeout )
    {
      while (timeout--)
      {
        asm("NOP");
        asm("NOP");
        asm("NOP");
      }
    }
    
    void SPI_send(unsigned char cs_pin, unsigned char *buffer, unsigned short length) 
    {
    	unsigned short i;
        ED_CS = LOW;
    	// send all data
    	for (i = 0; i < length; ++i) 
    	{
    		spitransfer(*buffer++);
            //MicroWait(2);
    	}
        ED_CS = HIGH;
        MicroWait(10);
    }
    
    void init_io(void)
    {
    	ED_CS	   = HIGH;	
    	PANEL_ON   = LOW;	
    	BORDER     = LOW;
    	DISCHARGE  = LOW;
    	PWM        = LOW;
    	RESET_PIN  = LOW;
    }
    
    void spitransfer(unsigned char val)
    {
        //unsigned char rsp;
        
       // ED_CS = LOW;
         spiwrite(val);
      //  ED_CS = HIGH;
        //return rsp;
    }
    
    void init_EPD(void)
    {
    	
      /*TBRN
        MAKE ALL PIN as O/p EXCEPT BUSY WHICH IS INPUT*/
        P0SEL |= 0x2C;
        P0DIR |= 0xD3;
        P1SEL = 0xF0;
        P1DIR = 0x0F;
     
    	init_io();
    	GT_UnSelect();
    	//SD_CS	   = HIGH;	
    	/*init the SPI Communication*/
    	memset(epaper_image, 0, sizeof(epaper_image));
    }
    
    void GT_UnSelect(void)
    {
        GT20L16_CS = HIGH;
    }
    
    void GT_Select(void)
    {
       GT20L16_CS = LOW;
    }
    
    unsigned long getAddrFromUnicode(unsigned int uniCode)
    {
       unsigned long Address;
       unsigned int BaseAdd=0;
         
        if (uniCode <= 45632)   // char
        {
            if(uniCode>=0x20&&uniCode<=0x7f)
            Address=16*(uniCode-0x20)+BaseAdd;
            else if(uniCode>=0xa0&&uniCode<=0xff)
            Address=16*(96+uniCode-0xa0)+BaseAdd;
            else if(uniCode>=0x100&&uniCode<=0x17f)
            Address=16*(192+uniCode-0x100)+BaseAdd;
            else if(uniCode>=0x1a0&&uniCode<=0x1cf)
            Address=16*(320+uniCode-0x1a0)+BaseAdd;
            else if(uniCode>=0x1f0&&uniCode<=0x1ff)
            Address=16*(368+uniCode-0x1f0)+BaseAdd;
            else if(uniCode>=0x210&&uniCode<=0x21f)
            Address=16*(384+uniCode-0x210)+BaseAdd;
            else if(uniCode>=0x1ea0&&uniCode<=0x1eff)
            Address=16*(400+uniCode-0x1ea0)+BaseAdd;
            else if(uniCode>=0x370&&uniCode<=0x3cf)
            Address=16*(496+uniCode-0x370)+BaseAdd;
            else if(uniCode>=0x400&&uniCode<=0x45f)
            Address=16*(592+uniCode-0x400)+BaseAdd;
            else if(uniCode>=0x490&&uniCode<=0x4ff)
            Address=16*(688+uniCode-0x490)+BaseAdd;
            else if(uniCode>=0x590&&uniCode<=0x5ff)
            Address=16*(800+uniCode-0x100)+BaseAdd;
            else if(uniCode>=0xe00&&uniCode<=0xe7f)
            Address=16*(912+uniCode-0xe00)+BaseAdd;
            else  Address=BaseAdd;
           // return Address;
        }
        return Address;
       /* else
        {
            unsigned long  ZFAdd,HZAdd;
            unsigned char  MSB,LSB;
            unsigned long ChineseTab;
            unsigned int data;
            unsigned long  Add_Chinese;
            MSB = uniCode>>8;
            LSB = uniCode;
            ZFAdd=36224;
            HZAdd=93452;
            ChineseTab=87436;
    
            if(MSB>=0xA1&&MSB<=0xA5)  //char area
            {
                if(MSB==0xA1&&LSB>=0xA1&&LSB<=0xBF)
                Add_Chinese=32*(LSB-0xA1)+ZFAdd;
                else if(MSB==0xA3&&LSB>=0xA1&&LSB<=0xFE)
                Add_Chinese=32*(31+LSB-0xA1)+ZFAdd;
                else if(MSB==0xA4&&LSB>=0xA1&&LSB<=0xF3)
                Add_Chinese=32*(125+LSB-0xA1)+ZFAdd;
                else if(MSB==0xA5&&LSB>=0xA1&&LSB<=0xF6)
                Add_Chinese=32*(208+LSB-0xA1)+ZFAdd;
                else
                Add_Chinese=ZFAdd;
            }
            else if((MSB>=0xB0&&MSB<=0xD7)&&(LSB>=0xA1&&LSB<=0xFE)) //chinese 5720
    
            {
                Add_Chinese=(MSB-176)*94+(LSB-161)+1;
                Add_Chinese=Add_Chinese*32 +HZAdd;
    
            }
            else if((MSB>=0xD8&&MSB<=0xF7)&&(LSB>=0xA1&&LSB<=0xFE)) //chinese 5720~6763
            {
                Add_Chinese=(MSB-0xD8)*94+(LSB-0xA1);
                Add_Chinese=Add_Chinese*2+ChineseTab;
                data=GTRead(Add_Chinese);
                Add_Chinese=32*data+HZAdd;
            }
            return Add_Chinese;
        }*/
    }
    
    int getMatrixUnicode(unsigned int uniCode, unsigned char *matrix, char Num_tries)
    {
        unsigned char i;
        unsigned long Add=0;
        unsigned char dtaLen = 0;
    	char a = 1;
        
        if (Num_tries == 1)
        {
            a = a + 1;
        }
        if(matrix == NULL)
    		return 0;
        
        //spi_on();
        if(uniCode <= 45632 )
        {
            dtaLen = 16;
        }
        else
        {
            dtaLen = 32;
        }  
        Add=getAddrFromUnicode(uniCode);
        MicroWait(5000);
        //MicroWait(5000);
      //  while(a)
       // {
            GT_Select();
            spiwrite(0x03);
            spiwrite(Add>>16);
            spiwrite(Add>>8);
            spiwrite(Add);
            spiBitOrder(LSB);
            for(i=0;i<dtaLen;i++)
            {	
                matrix[i]=spiwrite(0x00); /*save dot matrix data in matrixdata[i]*/
                MicroWait(1);
            }
            a--;
            GT_UnSelect();
            MicroWait(1);
       // }
        spiBitOrder(MSB);
        return dtaLen;
    }
    
    unsigned char putPixel(int x, int y, unsigned char pixel)
    {
    	int bit;
        int byte;
        int mask;
        unsigned char tmp;
    	
        if(x>DISP_LEN || y>DISP_WIDTH)
    		return 1;
        
        bit = x & 0x07;
        byte = (x>>3) + y * BYTES_PER_LINE;
        mask = 0x01 << bit;
        tmp = epaper_image[byte];
        if((tmp & mask) == (pixel << bit))
        {
            return 1;
        }
        if (BLACK == pixel)
        {
            epaper_image[byte] |= mask;
        }
        else
        {
            epaper_image[byte] &= ~mask;
        }
        return 0;
    }
    
    int drawUnicode(unsigned int uniCode, int x, int y, char tr)
    {
        int dtaLen;
        int pX      = 0;
        int pY      = 0;
        int color   = 0;
    	int k,j,i;
        
        memset(tMatrix, 0, sizeof(tMatrix));
        dtaLen = getMatrixUnicode(uniCode, tMatrix, tr);
        
        //spi_on();
        for(k = 0; k<2; k++)
        {
            for(i=0; i<8; i++)
            {
                for(j=0; j<(dtaLen/2); j++)
                {
    
                    if(tMatrix[j+(dtaLen/2)*k] & (0x01<<(7-i)))
                    {  
                        color = 1;
                    }
                    else
                    {
                        color = 0;
                    }
                    
                    pX = x + j;
                    pY = y + k*8+i;
                    
                    
                    putPixel(pX, pY, color);
                }
            }
        }
        return dtaLen/2;        // x +
    }
    
    /*Returns how many character drawn*/
    int drawString(char *string, int poX, int poY)
    {
    	int sumX = 0;
    	int xPlus;
        char strNum = 0;
    
        while(*string)
        {
            strNum++;
            xPlus = drawUnicode((int)*string, poX, poY, strNum);
            sumX += xPlus;
            *string++;
            
            if(poX < 200)
            {
                poX += xPlus;                                     /* Move cursor right            */
            }
        }
        return sumX;
    }
     
    void PWM_start(void)
    {
    	PWM = 1;
    	MicroWait(5000);
    	PWM = 0;
    	MicroWait(5000);
    }
    
    void PWM_stop(void)
    {
    	PWM = 0;
    }
    
    /*void SPI_ON(void)
    {
    	SPI_Init();
    	spiwrite(0x00);
    	spiwrite(0x00);
    	MicroWait(10);
    }*/
    	
    void Process_Init(void)
    {
    	RESET_PIN   =  LOW;
    	PANEL_ON	=  LOW;
    	DISCHARGE	=  LOW;
    	BORDER		=  LOW;
    	ED_CS		=  LOW;   
    //	PWM_start();
         //SPI_ON();//TBN
    	MicroWait(5000);
    	PANEL_ON =  HIGH;
    	MicroWait(10000);
    	RESET_PIN   =  HIGH;
    	BORDER      =  HIGH;
    	ED_CS		=  HIGH;
    	MicroWait(5000);
    	RESET_PIN   =  LOW;
    	MicroWait(5000);
    	RESET_PIN   =  HIGH;
    	MicroWait(5000);
    	// wait for COG to become read
    	while ( BUSY_PIN == LOW) {
    	}
    	// channel select
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x01), 2);
    	SPI_send(ED_CS, channel_select, sizeof(channel_select));
    	// DC/DC frequency
    	SPI_send(ED_CS, CU8(0x70, 0x06), 2);
    	SPI_send(ED_CS, CU8(0x72, 0xff), 2);
    	// high power mode osc
    	SPI_send(ED_CS, CU8(0x70, 0x07), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x9d), 2);
    	// disable ADC
    	SPI_send(ED_CS, CU8(0x70, 0x08), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x00), 2);
    	// Vcom level
    	SPI_send(ED_CS, CU8(0x70, 0x09), 2);
    	SPI_send(ED_CS, CU8(0x72, 0xd0, 0x00), 3);
    	// gate and source voltage levels
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	SPI_send(ED_CS, gate_source, sizeof(gate_source));
    	MicroWait(5000); //???
    	// driver latch on
    	SPI_send(ED_CS, CU8(0x70, 0x03), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x01), 2);
    	// driver latch off
    	SPI_send(ED_CS, CU8(0x70, 0x03), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x00), 2);
    	MicroWait(5000);
    	// charge pump positive voltage on
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x01), 2);
    	// final delay before PWM off
    	MicroWait(10000);
        MicroWait(10000);
        MicroWait(10000);
    	//PWM_stop();
    	// charge pump negative voltage on
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x03), 2);
    	MicroWait(10000);
        MicroWait(10000);
        MicroWait(10000);
    	// Vcom driver on
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x0f), 2);
        MicroWait(10000);
    	MicroWait(10000);
    	MicroWait(10000);
    	// output enable to disable
    	SPI_send(ED_CS, CU8(0x70, 0x02), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x24), 2);
    }
    
    static void SPI_put_wait(unsigned char c, int busy_pin) {
    
    	spitransfer(c);
    
    	// wait for COG ready
    	while (BUSY_PIN == LOW) {
    	}
        MicroWait(10);
    
    }
    void line_print(unsigned short line, unsigned char *data, unsigned char fixed_value,
                                                 bool read_progmem, EPD_stage stage) 
    {
    	// charge pump voltage levels
        unsigned short b;
    	unsigned short pixels;
    	unsigned char p1;
    	unsigned char p2;
    	unsigned char p3;
    	unsigned char p4;
    	
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	SPI_send(ED_CS, gate_source, sizeof(gate_source));
    
    	// send data
    	SPI_send(ED_CS, CU8(0x70, 0x0a), 2);
        MicroWait(5);
    	// CS low
        ED_CS = LOW;
    	SPI_put_wait(0x72, BUSY_PIN);
    
    	// even pixels
    	for (b = BYTES_PER_LINE; b > 0; --b) 
        {
    		if (0 != data) 
    		{
    			if (read_progmem) 
                {
    				//pixels = pgm_read_byte_near(data + b - 1) & 0xaa;
    			} 
                else 
                {
    				pixels = data[b - 1] & 0xaa;
    			}
                
    			switch(stage)
                {
                    case EPD_compensate:  // B -> W, W -> B (Current Image)
                        pixels = 0xaa | ((pixels ^ 0xaa) >> 1);
                        break;
                        
                    case EPD_white:       // B -> N, W -> W (Current Image)
                        pixels = 0x55 + ((pixels ^ 0xaa) >> 1);
                        break;
                        
                    case EPD_inverse:     // B -> N, W -> B (New Image)
                        pixels = 0x55 | (pixels ^ 0xaa);
                        break;
                        
                    case EPD_normal:       // B -> B, W -> W (New Image)
                        pixels = 0xaa | (pixels >> 1);
                        break;
    			}
                
    			SPI_put_wait(pixels, BUSY_PIN);
                //delay(10);
    		} 
            else
            {
    			SPI_put_wait(fixed_value, BUSY_PIN);
    		}	
        }
    
    	// scan line
    	for (b = 0; b < BYTES_PER_SCAN; ++b) 
        {
    		if (line / 4 == b) 
            {
    			SPI_put_wait(0xc0 >> (2 * (line & 0x03)), BUSY_PIN);
    		} 
            else 
            {
    			SPI_put_wait(0x00, BUSY_PIN);
    		}
            //delay(10);
    	}
    
    	// odd pixels
    	for (b = 0; b < BYTES_PER_LINE; ++b) 
        {
    		if (0 != data) 
            {
    			// AVR has multiple memory spaces
    			pixels = 0;
    			if (read_progmem) 
                {
    				//pixels = pgm_read_byte_near(data + b) & 0x55;
    			} else 
                {
    				pixels = data[b] & 0x55;
    			}
                
    			switch(stage) 
                {
                    case EPD_compensate:  // B -> W, W -> B (Current Image)
                        pixels = 0xaa | (pixels ^ 0x55);
                        break;
                    case EPD_white:       // B -> N, W -> W (Current Image)
                        pixels = 0x55 + (pixels ^ 0x55);
                        break;
                    case EPD_inverse:     // B -> N, W -> B (New Image)
                        pixels = 0x55 | ((pixels ^ 0x55) << 1);
                        break;
                    case EPD_normal:       // B -> B, W -> W (New Image)
                        pixels = 0xaa | pixels;
                        break;
    			}
    			p1 = (pixels >> 6) & 0x03;
    			p2 = (pixels >> 4) & 0x03;
    			p3 = (pixels >> 2) & 0x03;
    			p4 = (pixels >> 0) & 0x03;
    			pixels = (p1 << 0) | (p2 << 2) | (p3 << 4) | (p4 << 6);
    			SPI_put_wait(pixels, BUSY_PIN);
    		} 
            else 
            {
    			SPI_put_wait(fixed_value, BUSY_PIN);
    		}
            //delay(10);
    	}
        SPI_put_wait(0x00, BUSY_PIN);
        ED_CS = HIGH;
        MicroWait(10);
         //output data to panel
        SPI_send(ED_CS, CU8(0x70, 0x02), 2);
    	SPI_send(ED_CS, CU8(0x72, 0x2f), 2);
    }
    
    void frame_fixed(unsigned char fixed_value, EPD_stage stage) 
    {
    	unsigned char line;
    	
    	for ( line = 0; line < LINES_PER_DISPLAY; ++line) 
        {
    		line_print(line, (unsigned char*)0, fixed_value, false, stage);
            MicroWait(2);
    	}
        count = 0;
    }
    
    void frame_fixed_repeat(unsigned char fixed_value, EPD_stage stage) 
    {
    	//long stage_time = this->factored_stage_time;
    	
    	//do {
    		
    		//unsigned long t_start = millis();
    		frame_fixed(fixed_value, stage);
    		//unsigned long t_end = millis();
    		//if (t_end > t_start) {
    		//	stage_time -= t_end - t_start;
    		//} else {
    		//	stage_time -= t_start - t_end + 1 + ULONG_MAX;
    	//	}
    //	} while (stage_time > 0);
    }
    
    void frame_sram(unsigned char *image, EPD_stage stage)
    {
    	unsigned char line;
    	
    	for (line = 0; line < LINES_PER_DISPLAY ; ++line) 
        {
    		if(line * BYTES_PER_LINE <= (sizeof(epaper_image) - BYTES_PER_LINE))
    		{
    			line_print(line, &image[line * BYTES_PER_LINE], 0, false, stage);
    		}
    		else
    		{
    			line_print(line, (unsigned char*)0, 0, false, stage);
    		}
    	}
    }
    
    void frame_sram_repeat(unsigned char *image, EPD_stage stage) 
    {
    	int i;
    	
        //for(i=0; i<7; i++)
    	//{
    		frame_sram(image, stage);
    	//}
    }
    
    
    void image_sram(void) 
    {
    	frame_fixed_repeat(0xaa, EPD_compensate);
    	frame_fixed_repeat(0xaa, EPD_white);
    	frame_sram_repeat(epaper_image, EPD_inverse);
    	frame_sram_repeat(epaper_image, EPD_normal);
    }
    
    void Process_End(void)
    {
    	line_print(0x7fffu, 0, 0x55, false, EPD_normal);
    	MicroWait(10000);
    	BORDER = LOW;
    	MicroWait(10000);
    	BORDER = LOW;;
    	// latch reset turn on
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x03), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x01), 2);
    
    	// output enable off
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x02), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x05), 2);
    
    	// Vcom power off
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x0e), 2);
    
    	// power off negative charge pump
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x02), 2);
    
    	// discharge
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x0c), 2);
    
    	MicroWait(5000);
    
    	// all charge pumps off
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x05), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x00), 2);
    
    	// turn of osc
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x07), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x0d), 2);
    
    	// discharge internal - 1
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x50), 2);
    
    	MicroWait(500);
    
    	// discharge internal - 2
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0xA0), 2);
    
    	MicroWait(10000);
    
    	// discharge internal - 3
    	SPI_send(ED_CS, CU8(0x70, 0x04), 2);
    	MicroWait(10);
    	SPI_send(ED_CS, CU8(0x72, 0x00), 2);
    	// turn of power and all signals
        //
    
        MicroWait(5);
    	RESET_PIN = LOW;
    	PANEL_ON  = LOW;
    	BORDER    = LOW;
    	DISCHARGE = HIGH;
    	MicroWait(18000);
    	DISCHARGE = LOW;
        ED_CS = HIGH;
    }
    
    void Display_Epaper(void)
    {
        Process_Init();
    	image_sram();
    	Process_End();
    }
    	
    	
    #include<ioCC2530.h>
    #include "hal_types.h"
    #include "SPI.h"
    
    
    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;
        
        //Port0 configuration as GPIO and output :: P0_0 : Reset and P0_1 : Data or Command selection
    }
    
    byte spiwrite(uint8 c)
    {
         
           U0CSR &= ~(0x04 | 0x02);
           U0DBUF = c; 
           while( !(U0CSR & 0x02) ); 
           return U0DBUF;
    }
    
    void spiBitOrder(uint8 bit)
    {
        if(bit == MSB)
        {
            U0GCR |= 0x20;
        }
        else
        {
            U0GCR &= ~0x20;
        }
    }		
    char spiread(void)
    {
      spiwrite(0xFF);
      return U0DBUF;
    }   
        
        
        
    
    
    
    
    
    
    
    
    
    
    
    
       
    

    void image_sram(void)
    {
    frame_fixed_repeat(0xaa, EPD_compensate);
    frame_fixed_repeat(0xaa, EPD_white);
    frame_sram_repeat(epaper_image, EPD_inverse);
    frame_sram_repeat(epaper_image, EPD_normal);
    }

    Spi Hangs in frame_sram_repeat(epaper_image, EPD_inverse), some timesframe_fixed_repeat(0xaa, EPD_white). 

  • You application code is too complicate for me to do reading and debugging for you. I would suggest you to set some breakpoints to lock down where the problem is and I can help accordingly.