How to initialize the spi2 function of the MC9S12XEP100, I have initialized the initialization spi0 and spi1, but when I initialize spi2, there is no way to initialize successfully using the same method. I suspect that the values of some registers are not set, so I would like to consult. Below is my code.
void SPI2_Init(void)
{
DDRT = 0xff;
DDRH_DDRH7 = 1;
MODRR_MODRR6 = 1;
SPI2CR1 = 0x5e; //使能SPI,禁止中断,时钟高有效,相位为0;
SPI2CR2 = 0x10; //SS管脚为普通I/O,双向模式,16bit;
SPI2BR = 0x42; //设置SPI时钟频率为42 1 41 2 40 4MHz;
}
unsigned char SPI0_Read_Byte(void)
{
while (!SPI2SR_SPTEF); //等待发送器空
(void)SPI2SR;
SPI2DRL = 0xff;
while (!SPI2SR_SPIF); //等待发送完成
(void)SPI2SR;
(void)SPI2DRL;
return SPI2DRL;
}
void SPI0_Send_Byte(unsigned char val)
{
while (!SPI2SR_SPTEF); //等待发送器空
(void)SPI2SR;
SPI2DRL = val;
while (!SPI2SR_SPIF); //等待发送完成
(void)SPI2SR;
(void)SPI2DRL;
}
Hi,
Please refer to S12X Examples Pack. There are the examples for the S12XEP100 - SPI.
I hope it helps you.
Best regards,
Diana