/* SPI4 init function */
void MX_SPI4_Init(void)
{
hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_16BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi4.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi4.Init.NSS = SPI_NSS_SOFT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLED;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
hspi4.Init.CRCPolynomial = 10;
HAL_SPI_Init(&hspi4);
}
SPI 配置
uint16_t SendRece(uint16_t data)
{
uint8_t txb[2];
uint8_t rxb[2]={0,0};
txb[1] = data>>8;
txb[0] = data&0x00ff;
HAL_SPI_TransmitReceive(&hspi4,txb,rxb,1,20000);
//HAL_SPI_TransmitReceive(&hspi4,&txb[0],&rxb[0],2,20000);
//HAL_SPI_TransmitReceive(&hspi4,&txb[0],&rxb[1],1,20000);
data = rxb[1];
data = data<<8;
data = data+rxb[0];
return data;
}
void TLC3548Init(void)
{
uint16_t rbuff;
uint16_t rrbuff[8];
SPINCTRL1;
SPINSS0;
rbuff=SendRece(0xa000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0xa240);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x0000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x1000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x2000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x3000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x4000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x5000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x6000);//0xa040
SPINSS1;
tlcdelay();
SPINSS0;
rbuff=SendRece(0x7000);//0xa040
SPINSS1;
//tlcdelay();
tlcdelay();
SPINSS0;
rrbuff[0]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[1]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[2]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[3]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[4]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[5]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[6]=SendRece(0xe000);
SPINSS1;
tlcdelay();
SPINSS0;
rrbuff[7]=SendRece(0xe000);
SPINSS1;
tlcdelay();
}
读取
[img]D:\Desktop\IMG_20150807_190837.JPG[/img]
D:\Desktop\IMG_20150807_190958.JPG
D:\Desktop\IMG_20150807_191011.JPG
波形图
1 clk
2MOSI
3MISO
4NSS
读出的数据 一直是 0x0000 要么就是 0XFEFE 只有这两种数据 请大家帮忙看看
|