本帖最后由 jpxuchao 于 2015-12-15 15:15 编辑
我想问一下spi的引脚要不要配置上拉或者下拉,下面是我的配置程序:
SIM_SCGC6 |= SIM_SCGC6_SPI0_MASK;
SIM->SCGC5|=SIM_SCGC5_PORTE_MASK;
PORTE_PCR16 |=PORT_PCR_MUX(2)|PORT_PCR_PS_MASK;
PORTE_PCR17 |=PORT_PCR_MUX(2)|PORT_PCR_PS_MASK;
PORTE_PCR18 |=PORT_PCR_MUX(2)|PORT_PCR_PS_MASK;
PORTE_PCR19 |=PORT_PCR_MUX(2)|PORT_PCR_PS_MASK;
SPI0_MCR &= ~SPI_MCR_MDIS_MASK;
SPI0_MCR |=SPI_MCR_MSTR_MASK
|SPI_MCR_CONT_SCKE_MASK
|SPI_MCR_CLR_TXF_MASK
|SPI_MCR_CLR_RXF_MASK
|SPI_MCR_DIS_TXF_MASK
|SPI_MCR_DIS_RXF_MASK
|SPI_MCR_HALT_MASK;
SPI0_CTAR0 &= ~SPI_CTAR_FMSZ_MASK;
SPI0_CTAR0 |= SPI_CTAR_FMSZ(7);
// SPI0_CTAR0 |= SPI_CTAR_LSBFE_MASK; //LSB
SPI0_CTAR0 &= ~SPI_CTAR_LSBFE_MASK; //MSB
/********MODE select*********/
SPI0_CTAR0 |= SPI_CTAR_CPOL_MASK;
// SPI0_CTAR0 &= ~SPI_CTAR_CPOL_MASK;
SPI0_CTAR0 |= SPI_CTAR_CPHA_MASK;
// SPI0_CTAR0 &= ~SPI_CTAR_CPHA_MASK;
SPI0->SR = 0xFFFFFFFF;
SPI0_CTAR0 |= SPI_CTAR_PBR(2)|SPI_CTAR_BR(4);
SPI0_CTAR0 |= SPI_CTAR_ASC(1)|SPI_CTAR_CSSCK(1)|SPI_CTAR_PASC(1)|SPI_CTAR_PCSSCK(1);
SPI0_SR |= SPI_SR_TXRXS_MASK;
while(1)
{
SPI0_MCR &= ~SPI_MCR_HALT_MASK;
SPI_ReadWriteByte(0xF0);
SPI_ReadWriteByte(0xAA);
SPI_ReadWriteByte(0x55);
delay(5);
}
}
当我发送数据的时候,它的结果是:
见SPI结果,帮我分析一下为什么数据拉不低。
|