Hello, and welcome to the forum.
Unfortunately, my Chinese is non-existent, so I cannot be sure of your difficulty.
I gather that the SPI module has been set up for 8-bit operation (assuming 16-bit operation is also available for the particular device). Your code suggests that 8-bit operation is actually required. However, I can see that your parameters and the variable are 16-bit size. It would be preferred to match these to the actual data size.
#define SPI_send(x) (void)SPI_transfer(x)#define SPI_recv() SPI_transfer(0xFF) // Returns received valueunsigned char SPI_transfer( unsigned char val){ while (!SPI0SR_SPTEF); SPI0DRL = val; while (!SPI0SR_SPIF); return SPI0DRL;} unsigned char SPI_Read_Reg_mma7455( unsigned char ucReg){ unsigned char ucTemp; MMA_CS = 0; // CS = 0 SPI_send( (ucReg & 0x3F) << 1); ucTemp = SPI_recv(); MMA_CS = 1; // CS = 1 return ucTemp;}void SPI_Write_Reg_mma7455( unsigned char ucReg, unsigned char ucValue){ MMA_CS = 0; // CS = 0 SPI_send( ((ucReg & 0x3F) << 1) | 0x80); SPI_send( ucValue); MMA_CS = 1; // CS = 1}
Another issue may be whether you have set the CPHA and CPOL bits to suit the MMA7455? I believe that CPHA = 0, CPOL = 0 is required.
Regards,
Mac