工具/软件:Code Composer Studio
您好!
我正在尝试使用 CCS 设置 TM4C123GH6PM LaunchPad 和 DHT11温度传感器之间的连接。 我从电路板发送开始信号、但在接收阶段遇到困难、因为我总是返回 一个高电平脉冲、当它应该是80us 低电平脉冲、然后是80us 高电平脉冲。 我的代码基于传感器制造商提供的库: https://github.com/adafruit/DHT-sensor-library。 下面包含了有关不断变化的脉冲的信息。 请提供帮助,感谢您的参与! 以下是我的开发代码:
/**
* main.c
*
#include
#include
#include
#include
//#include "DHT.h"
#include "DelayTimer.h"
#include "debug.h"
#include "inc/hw_ints.h"
#include "inc/hw_timer.h"
#include "inc/hw_types.h"
#include "inc/hw_NVIC.h"
#include "inc/hw_memmap.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "driverlib/uart.h"
#include "driverlib/gpio.h"
#include "uartstdio.h"
uint32_t 预期脉冲(bool 级别);
int main (空)
{
//启动系统时钟
SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHz);
//启动端口 D 外设
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOD);
///----------------------------------
//启用外设 GPIOA 和 UART0
//
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);
SysCtlPeripheralEnable (SYSCTL_Periph_UART0);
//配置使引脚 A0用作 UART0 Rx,A1用作 UART0 Tx
GPIOPinConfigure (GPIO_PA0_U0RX);
GPIOPinConfigure (GPIO_PA1_U0TX);
//定义 GPIOA 的哪些引脚用作 UART
GPIOPinTypeUART (GPIO_Porta_base、GPIO_PIN_0 | GPIO_PIN_1);
//将 UART0的波特率时钟源设置为精密内部 OSC
UARTClockSourceSet (UART0_BASE、UART_CLOCK_PIOSC);
//函数声明位于 uartstdio.c 中 在本例中、我们将115200的波特率和16MHz 的 OSC 频率传递给 UART0
UARTStdioConfig (0、115200、16000000);
///------------------------------------------
timerInit();
uint32_t cycles[80]、i;
uint8_t data[5];
//重置数据
DATA[0]= DATA[1]= DATA[2]= DATA[3]= DATA[4]= 0;
DBG ("DHT11示例\n");
while (1){
ROM_GPIOPinTypeGPIOInput (GPIO_PORTD_BASE、GPIO_PIN_0);
///ROM_GPIOPadConfigSet (GPIO_PORTD_base、GPIO_PIN_0、GPIO_Strength _2mA、GPIO_PIN_TYPE_STD_WPU);
ROM_GPIOPinWrite (GPIO_PORTD_base、GPIO_PIN_0、1);
延迟(250);
ROM_GPIOPinWrite (GPIO_PORTD_base、GPIO_PIN_0、0);
延迟(20);
ROM_GPIOPinWrite (GPIO_PORTD_base、GPIO_PIN_0、1);
delayMicroseconds (40);
ROM_GPIOPinTypeGPIOOutput (GPIO_PORTD_base、GPIO_PIN_0);
delayMicroseconds (10);
if (!expectPulse (false)){
DBG ("等待启动信号低脉冲的超时\n");
}
if (!expectPulse (true)){
DBG ("等待启动信号高电平脉冲的超时\n");
}
}
返回0;
}
//--------------------------------------
uint32_t expectPulse (bool 级别){
uint32_t 计数= 0;
while (ROM_GPIOPinRead (GPIO_PORTD_base、GPIO_PIN_0)==电平){
如果(count++>=1000){
返回0;
}
}
返回计数;
}