STM32F103C8T6与TLC5618实现DA输出功能,现在问题是TLC5618没有任何输出,OUTA和OUTB输出都是0V,
找不到问题原因,希望高手能指点一下软硬件方面有什么错误。
原理图:
STM32F103C8T6 SPI1
TLC5618时序图和表格
TLC5618输入数据格式
TLC5618数据格式
代码:
(1)SPI1初始化:
void SPI1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 |GPIO_Pin_6| GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;//单工输出
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //主机模式
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; //16位SPI
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //时钟悬空高电平
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //在第一个时钟(下降沿)采集数据
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //Nss使用软件控制
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//从最高位开始传输
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Cmd(SPI1, ENABLE);
SPI_Init(SPI1, &SPI_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7);
GPIO_SetBits(GPIOA,GPIO_Pin_5);
}
(2)TLC5618 DA输出函数
#define DA_Start() GPIO_ResetBits(GPIOA,GPIO_Pin_4)
#define DA_End() GPIO_SetBits(GPIOA,GPIO_Pin_4)
void DA_Output(uint16_t v0,uint16_t v1)
{
DA_Start();
SPI1_WriteReadData(0x0000|(v1&0x0FFF));
DA_End();
DelayMS(1);
DA_Start();
SPI1_WriteReadData(0x8000|(v0&0x0FFF));
DA_End();
}
一周热门 更多>