AnsweredAssumed Answered

bf533 spi

Question asked by wanjin3 on Mar 4, 2014
Latest reply on Mar 9, 2014 by wanjin3

this is a programmer using bf531 with a chip named ch432.

 

 

bf531 : spi master

ch432 : spi slave

 

 

problem: when i select  the ship  ch432, the cs is not do as i want.

code:the red colour is problem codes:

void SPI_Init(void)

{

      *pSPI_FLG  = 0xF708;                                                                                // sSPISEL3

               *pSPI_BAUD = BAUD_RATE_DIVISOR;

               *pSPI_CTL = (*pSPI_CTL|CPHA| CPOL|TIMOD01|MSTR);

               *pSPI_CTL = (*pSPI_CTL | SPE);

               asm("ssync;");

 

          }

 

void SPI_send_data(unsigned char data) 

          *pSPI_TDBR = data;

          asm("ssync;");

          while ((*pSPI_STAT & SPIF) == 0);

 

//SPI receive 

unsigned char SPI_receive_data(void) 

    SPI_send_data(0xFF);

    return (*pSPI_RDBR); 

}

 

void CH432_PORT_INIT( )  

{

 

    CH432_DIS();               // disalbe chip select

    mDelayuS(1);

 

}

 

 

UINT8  Spi432Exchange( UINT8 d )   

{  

    SPI_send_data(d);

}

 

 

#define Spi432OutByte( d )      Spi432Exchange( d )   

#define Spi432InByte( )         Spi432Exchange( 0xFF )  

 

 

void Spi432Start( UINT8 addr )  

{

    CH432_EN();                                        // ch432 chip enable

    Spi432OutByte( addr );

   CH432_DIS();                                           // ch432 disalbe

 

 

}

 

UINT8 ReadCH432Data( UINT8 mAddr )  

{

         UINT8 d;

         Spi432Start( ( mAddr<<2 ) &0xFD );  

 

         CH432_EN();                                   // ch432 chip enable

         d=SPI_receive_data();

        CH432_DIS();                                   // ch432 disalbe

         return( d );

}

 

from the pic below, upper line is sck  clock.

dowm line is ch432 select .

 

IMG_20140304_194026.jpg

IMG_20140304_194059.jpg

but i want it to be :

11.png

Attachments

Outcomes