写了一个驱动TLV1544的ADC驱动程序,但在主函数中调用TLV1544.c函数时,没有采集到输入的电压值,TLV1544.c函数如下,有大佬能看下是不是写的有啥不对的吗,非常感谢
#include "TLV1544.h"
#include "usart.h"
#include "delay.h"
void TLV1544_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//ê1ÄüGPIOAê±Öó
//Ïè3õê¼»ˉADC1í¨μà5 IO¿ú
GPIO_InitStructure.GPIO_Pin = CS;//PA4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//Ä£Äaêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SCLK;//PA5
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DIN;//PA6
GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_InitStructure.GPIO_Pin = DRDY;//PA5
// GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = DOUT;//PA7
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//Ä£Äaêäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
int set_TLV1544_mode(u16 channel)//éèÖÃTLV1544×a»»Ä£ê½
{
u16 i;
// uint8_t bit;
channel=channel<<4;
TLV1544_CS_L(); //0
delay_ms(5);
TLV1544_SCLK_L(); //0
delay_ms(5);
for(i=0;i<10;i++)
{
if(channel&0x80)
{
TLV1544_DIN_L();
}
else
TLV1544_DIN_H();
__NOP();
TLV1544_SCLK_L();
TLV1544_SCLK_H();
channel=channel<<1;
}
TLV1544_CS_H();
}
int TLV1544_tra(void) // ADC3õê¼»ˉoˉêy£¬êy¾YÎa10λ
{
u16 x=0,i;
int adc_value=0;
set_TLV1544_mode(1);//éèÖÃTLV1544×a»»Ä£ê½
delay_ms(60);
TLV1544_CS_L();
__NOP();
__NOP(); //3õê¼»ˉƬѡ
TLV1544_SCLK_L();//ê±Öóà-μí
__NOP();
__NOP();
for(i=0;i<10;i++)
{
TLV1544_SCLK_H();
__NOP();
x=GPIO_ReadInputDataBit(GPIOA,DOUT);
adc_value|=x;
adc_value<<=1;
TLV1544_SCLK_L();
__NOP();
__NOP();
}
// adc_value>>=1;
TLV1544_CS_H(); //1
if(adc_value >= 512)
adc_value=0;
//printf("---%d---
",adc_value);
return adc_value;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
什么意思,实际采电压的时候没有反应。。。
一周热门 更多>