[STM8] 请教大神:有做过STM8控制SHT10的程序吗?

[复制链接]
 楼主| sjg142729 发表于 2015-10-28 15:58 | 显示全部楼层 |阅读模式
请教大神:有做过STM8控制SHT10的程序吗?
zhuotuzi 发表于 2015-10-28 16:50 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:51 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:52 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:52 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:53 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:53 | 显示全部楼层
zhuotuzi 发表于 2015-10-28 16:54 | 显示全部楼层
不好意思,人家是图片格式,下载需要积分,我只能截图发来了,防止排版乱了顺序,我就一楼一楼的帖了程序。
734774645 发表于 2015-10-28 17:31 | 显示全部楼层
楼上的发错了那个是SHT21,楼主要的是SHT11,我来发个例程。
----------------
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f10x.h"
  3. #include "usart1.h"
  4. #include "stdio.h"
  5. /* Private typedef -----------------------------------------------------------*/

  6. /* Private define ------------------------------------------------------------*/
  7. #define SDA_H()         GPIO_SetBits(GPIOB,GPIO_Pin_0)
  8. #define SDA_L()         GPIO_ResetBits(GPIOB,GPIO_Pin_0)
  9. #define SCK_H()         GPIO_SetBits(GPIOB,GPIO_Pin_1)
  10. #define SCK_L()         GPIO_ResetBits(GPIOB,GPIO_Pin_1)
  11. //读SDA数据
  12. #define SDA_R()         GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)

  13. /* Private macro -------------------------------------------------------------*/
  14. #define noACK 0         //无应答
  15. #define ACK   1         //应答

  16. #define STATUS_REG_W    0x06   //000   0011    0
  17. #define STATUS_REG_R    0x07   //000   0011    1
  18. #define MEASURE_TEMP    0x03   //000   0001    1
  19. #define MEASURE_HUMI    0x05   //000   0010    1
  20. #define RESET           0x1e   //000   1111    0

  21. /* Private variables ---------------------------------------------------------*/
  22. enum {TEMP,HUMI};
  23. uint8_t Test_Timetick = 0;
  24. uint16_t Test_Counter = 0;
  25. /* Private function prototypes -----------------------------------------------*/
  26. void RCC_Config(void);
  27. void USART1_Config(void);
  28. void SHT10_Config(void);
  29. void SHT10_SDAIn(void);
  30. void SHT10_SDAOut(void);
  31. void SHT10_Delay(void);
  32. uint8_t SHT10_WriteByte(uint8_t value);
  33. uint8_t SHT10_ReadByte(uint8_t Ack);
  34. void SHT10_Start(void);
  35. void SHT10_ConReset(void);
  36. uint8_t SHT10_Measure(uint16_t* pValue, uint8_t* pCheckSum, uint8_t mode);
  37. void SHT10_Cal(uint16_t Temp,uint16_t Hum, float* pTempValue,float* pHumValue);

  38. /* Private functions ---------------------------------------------------------*/

  39. /**
  40.   * [url=home.php?mod=space&uid=247401]@brief[/url]  主程序
  41.   * @param  无
  42.   * @retval 无
  43.   */
  44. int main(void)
  45. {
  46.     //温度结果  16bit
  47.     uint16_t TempValue;
  48.     //湿度结果 16bit
  49.     uint16_t HumValue;
  50.     //温度转换结果
  51.     float TempResult;
  52.     //湿度转换结果
  53.     float HumResult;
  54.     //校验值
  55.     uint8_t CheckValue = 0x00;
  56.    
  57.     //错误
  58.     uint8_t error = 0x00;
  59.    
  60.     //初始化RCC
  61.     RCC_Config();
  62.     USART1_Config();
  63.     SHT10_Config();
  64.    
  65.     printf("Start\n");
  66.     while(1)
  67.     {
  68.         if(Test_Timetick)
  69.         {
  70.             Test_Timetick = 0;
  71.             Test_Counter ++;
  72.             
  73.             //延时2000ms
  74.             if(Test_Counter > 2000)
  75.             {
  76.                 Test_Counter = 0;
  77.                
  78.                 printf("启动转换!\n");
  79.                 //SHT10 连接
  80.                 SHT10_ConReset();
  81.                 //获得温度和湿度数据,16位格式
  82.                 error += SHT10_Measure(&TempValue,&CheckValue,TEMP);
  83.                 error += SHT10_Measure(&HumValue,&CheckValue,HUMI);
  84.                 //温度湿度计算,浮点数形式
  85.                 SHT10_Cal(TempValue ,HumValue,&TempResult,&HumResult);
  86.                 //通过串口输出,温度和湿度数据
  87.                 printf("温度 %2.1fC 湿度 %2.1f%%\n",TempResult,HumResult);

  88.             }
  89.         }
  90.     }
  91. }

  92. /**
  93.   * @brief  初始化Systick定时器
  94.   * @param  None
  95.   * @retval None
  96.   */
  97. void RCC_Config(void)
  98. {        
  99.     //Systick时钟每1ms触发一次
  100.     if (SysTick_Config(SystemCoreClock / 1000))
  101.     {
  102.         //
  103.         while (1);
  104.     }
  105. }

  106. /**
  107.   * @brief  初始化SHT10 IO口
  108.   * @param  None
  109.   * @retval None
  110.   */
  111. void SHT10_Config(void)
  112. {
  113.     GPIO_InitTypeDef GPIO_InitStructure;
  114.    
  115.     //使能GPIOA时钟
  116.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
  117.   
  118.     //PB0 SDA 推挽输出
  119.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  120.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  121.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  122.           GPIO_Init(GPIOB, &GPIO_InitStructure);
  123.           //PB1 SCK 推挽输出
  124.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  125.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   
  126.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  127.           GPIO_Init(GPIOB, &GPIO_InitStructure);
  128. }

  129. /**
  130.   * @brief  配置为输入状态
  131.   * @param  None
  132.   * @retval None
  133.   */
  134. void SHT10_SDAIn(void)
  135. {
  136.     GPIO_InitTypeDef GPIO_InitStructure;
  137.    
  138.     //PB0 SDA 浮动输入,外部有上拉电阻
  139.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  140.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  141.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  142.           GPIO_Init(GPIOB, &GPIO_InitStructure);   
  143. }

  144. /**
  145.   * @brief  配置为输出状态
  146.   * @param  None
  147.   * @retval None
  148.   */
  149. void SHT10_SDAOut(void)
  150. {
  151.           GPIO_InitTypeDef GPIO_InitStructure;
  152.    
  153.     //PB0 SDA 推挽输出
  154.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  155.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  156.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  157.           GPIO_Init(GPIOB, &GPIO_InitStructure);
  158. }

  159. /**
  160.   * @brief  配置为输出状态
  161.   * @param  写数据
  162.   * @retval 应答
  163.   */
  164. uint8_t SHT10_WriteByte(uint8_t value)
  165. {
  166.     uint8_t i,error=0;  
  167.     //SDA输出
  168.     SHT10_SDAOut();
  169.    
  170.     for( i = 0x80 ; i>0 ; i/=2)            
  171.     {
  172.         if ( i & value)
  173.             SDA_H();            
  174.         else
  175.             SDA_L();
  176.         
  177.         SHT10_Delay();                       
  178.         SCK_H();                          
  179.         SHT10_Delay();                       
  180.         SCK_L();
  181.         SHT10_Delay();                     
  182.     }
  183.    
  184.     //SDA输入
  185.     SHT10_SDAIn();
  186.    
  187.     SCK_H();                           
  188.     error = SDA_R();   //读应答位                 
  189.     SCK_L();
  190.    
  191.     return error;                 
  192. }

  193. /**
  194.   * @brief  读数据
  195.   * @param  应答
  196.   * @retval 返回数据
  197.   */
  198. uint8_t SHT10_ReadByte(uint8_t Ack)
  199. {
  200.     uint8_t i,val=0;
  201.     //输入状态
  202.     SHT10_SDAIn();  
  203.    
  204.     for (i=0x80;i>0;i/=2)         
  205.     {
  206.         SHT10_Delay();  
  207.         SCK_H();   
  208.         SHT10_Delay();  
  209.         if (SDA_R())
  210.             val=(val | i);        //读数据
  211.         SCK_L();                                          
  212.     }
  213.    
  214.     //输出状态
  215.     SHT10_SDAOut();  
  216.     if(Ack)
  217.         SDA_L();                //应答为低电平
  218.     else
  219.         SDA_H();

  220.     SHT10_Delay();  
  221.     SCK_H();                     
  222.     SHT10_Delay();  
  223.     SCK_L();
  224.     SHT10_Delay();                                             
  225.     return val;
  226. }

  227. /**
  228.   * @brief  启动
  229.   * @param  无
  230.   * @retval 无
  231.   */
  232. void SHT10_Start(void)
  233. {  
  234.    //SDA输出
  235.     SHT10_SDAOut();
  236.    
  237.     SCK_L();                  
  238.     SHT10_Delay();         
  239.     SCK_H();
  240.     SHT10_Delay();         
  241.     SDA_L();
  242.     SHT10_Delay();         
  243.     SCK_L();  
  244.     SHT10_Delay();         
  245.     SCK_H();
  246.     SHT10_Delay();         
  247.     SDA_H();                  
  248.     SHT10_Delay();         
  249.     SCK_L();                  
  250. }

  251. /**
  252.   * @brief  重新连接
  253.   * @param  无
  254.   * @retval 无
  255.   */
  256. void SHT10_ConReset(void)
  257. {
  258.     uint8_t i;
  259.     //输出
  260.     SHT10_SDAOut();
  261.    
  262.     SDA_H();    //输出高电平
  263.     SCK_L();
  264.    
  265.     for(i = 0 ; i < 9 ; i++)                  
  266.     {
  267.         SCK_H();
  268.         SHT10_Delay();
  269.         SCK_L();
  270.         SHT10_Delay();
  271.     }
  272.    
  273.     SHT10_Start();                  
  274. }

  275. /**
  276.   * @brief  软件重启
  277.   * @param  无
  278.   * @retval 无
  279.   */
  280. uint8_t SHT10_SoftReset(void)
  281. {
  282.     uint8_t error=0;  
  283.     SHT10_ConReset();              
  284.     error += SHT10_WriteByte(RESET);      
  285.     return error;                    
  286. }

  287. /**
  288.   * @brief  温度或湿度测量
  289.   * @param  温度或者湿度指针数据,校验值指针,模式
  290.   * @retval 错误
  291.   */
  292. uint8_t SHT10_Measure(uint16_t* pValue, uint8_t* pCheckSum, uint8_t mode)
  293. {
  294.     uint8_t error=0;
  295.    
  296.     uint8_t Value_H = 0;
  297.     uint8_t Value_L = 0;
  298.    
  299.     //启动
  300.     SHT10_Start();               
  301.     switch(mode)
  302.     {                     
  303.     case TEMP:
  304.         error += SHT10_WriteByte(MEASURE_TEMP);
  305.         break;
  306.     case HUMI:
  307.         error += SHT10_WriteByte(MEASURE_HUMI);
  308.         break;
  309.     default:
  310.         break;         
  311.     }
  312.    
  313.     //SDA读状态
  314.     SHT10_SDAIn();
  315.     //等待转换完成,代码有待优化
  316.     while(SDA_R())
  317.     {
  318.         ;
  319.     }

  320.     Value_H = SHT10_ReadByte(ACK);    //读高位
  321.     Value_L = SHT10_ReadByte(ACK);    //读低位
  322.    
  323.     *pCheckSum = SHT10_ReadByte(noACK);  //读校验结果
  324.    
  325.     //返回结果
  326.     *pValue = (Value_H << 8) | Value_L;   
  327.    
  328.     return error;
  329. }


  330. /**
  331.   * @brief  计算温度和湿度数据
  332.   * @param  温度数据 湿度数据 温度结果 湿度结果
  333.   * @retval 无
  334.   */
  335. void SHT10_Cal(uint16_t Temp,uint16_t Hum, float* pTempValue,float* pHumValue)
  336. {
  337.     const float d1 = -40.1;
  338.     const float d2 = 0.01;
  339.     float Temp_C;
  340.     //温度结果,换算                 
  341.     Temp_C = d1 + d2 * Temp;   
  342.    
  343.     const float C1 = -2.0468;           
  344.     const float C2 = +0.0367;           
  345.     const float C3 = -0.0000015955;     
  346.     const float T1 = +0.01;            
  347.     const float T2 = +0.00008;         
  348.    
  349.     //湿度线性值
  350.     float RH_Lin;
  351.     //湿度真实值
  352.     float RH_True;  
  353.    
  354.     //RH线性结果
  355.     RH_Lin = C1 + C2 * Hum + C3 * Hum *Hum;
  356.     RH_True = (Temp_C - 25) * (T1 + T2 * Hum) + RH_Lin;
  357.     //限定范围
  358.     if( RH_True > 100 ) RH_True = 100;
  359.     if( RH_True < 0.01) RH_True = 0.01;
  360.    
  361.     *pTempValue = Temp_C;
  362.     *pHumValue = RH_True;
  363.    
  364. }


  365. /**
  366.   * @brief  延时函数
  367.   * @param  无
  368.   * @retval 无
  369.   */
  370. void SHT10_Delay(void)
  371. {
  372.     //延时函数,i有待修改
  373.     for(uint16_t i = 500 ; i > 0 ; i--)
  374.     {
  375.         ;
  376.     }
  377. }


734774645 发表于 2015-10-28 17:32 | 显示全部楼层


在上传一个串口队列发送的代码,这个里面也使用到了!头文件部分




  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f10x.h"

  3. //函数声明
  4. void USART1_Config(void);
  5. uint8_t Add_Tx1Item(uint8_t ch);
  6. uint8_t Get_Tx1BufCounter(void);
  7. uint8_t Get_Rx1Item(void);
  8. uint8_t Get_Rx1BufCounter(void);
  9. void Clear_Tx1Buf(void);
  10. void Clear_Rx1Buf(void);
  11. #endif

  12. c文件部分
  13. /**
  14.   ******************************************************************************
  15.   * [url=home.php?mod=space&uid=288409]@file[/url]   
  16.   * [url=home.php?mod=space&uid=187600]@author[/url]  
  17.   * [url=home.php?mod=space&uid=895143]@version[/url]
  18.   * [url=home.php?mod=space&uid=212281]@date[/url]   
  19.   * @brief   以队列的方式发送和接收数据
  20.   ******************************************************************************
  21.   */
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "usart1.h"
  24. #include "stdio.h"
  25. #include "stm32f10x_it.h"
  26. /* Private typedef -----------------------------------------------------------*/
  27. /* Private define ------------------------------------------------------------*/
  28. /* Private macro -------------------------------------------------------------*/
  29. //发送缓冲区长度
  30. #define TX1_BUFFER_SIZE        128
  31. //接收缓冲区长度
  32. #define RX1_BUFFER_SIZE 128
  33. /* Private variables ---------------------------------------------------------*/
  34. //发送缓冲区
  35. uint8_t Tx1_Buffer[TX1_BUFFER_SIZE];
  36. uint8_t Tx1_WriteIndex = 0;
  37. uint8_t Tx1_ReadIndex = 0;
  38. uint8_t Tx1_Counter = 0;
  39. //接收缓冲区
  40. uint8_t Rx1_Buffer[RX1_BUFFER_SIZE];
  41. uint8_t Rx1_WriteIndex = 0;
  42. uint8_t Rx1_ReadIndex = 0;
  43. uint8_t Rx1_Counter = 0;
  44. uint8_t Rx1_BufOverflow = 0;
  45. /* Private function prototypes -----------------------------------------------*/
  46. /* Private functions ---------------------------------------------------------*/

  47. /**
  48.   * @brief  USART1_Config 初始化USART1
  49.   *         第一步 使能GPIOA时钟
  50.   *         第二步 配置IO口
  51.   *         第三步 配置USART1
  52.   *         第四步 配置中断优先级
  53.   * @param  None
  54.   * @retval None
  55.   */
  56. void USART1_Config(void)
  57. {
  58.     USART_InitTypeDef USART_InitStructure;
  59.     GPIO_InitTypeDef GPIO_InitStructure;
  60.    
  61.     Clear_Tx1Buf();
  62.     Clear_Rx1Buf();
  63.    
  64.     //使能GPIOA时钟
  65.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA \
  66.                         | RCC_APB2Periph_USART1 ,ENABLE);
  67.   
  68.     //PA9 TX1 复用推挽输出
  69.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  70.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  71.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  72.           GPIO_Init(GPIOA, &GPIO_InitStructure);
  73.           //PA10 RX1 浮动输入
  74.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  75.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   
  76.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  77.           GPIO_Init(GPIOA, &GPIO_InitStructure);
  78.   
  79.     USART_InitStructure.USART_BaudRate = 9600;
  80.     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  81.     USART_InitStructure.USART_StopBits = USART_StopBits_1;
  82.     USART_InitStructure.USART_Parity = USART_Parity_No;
  83.     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  84.     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  85.     USART_Init(USART1, &USART_InitStructure);
  86.     //使能接收中断
  87.         USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  88.     //使能USART1
  89.         USART_Cmd(USART1, ENABLE);
  90.    
  91.     //配置USART1中断,最高优先级
  92.     NVIC_InitTypeDef NVIC_InitStructure;
  93.           //抢占优先级0  
  94.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  95.           //从优先级1
  96.           NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  97.           NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  98.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  99.           NVIC_Init(&NVIC_InitStructure);

  100. }

  101. /**
  102.   * @brief  加入发送队列.
  103.   * @param  待发送的数据
  104.   * @retval 待发送的数据
  105.   */
  106. uint8_t Add_Tx1Item(uint8_t ch)
  107. {
  108.         //发送队列满。发送队列满
  109.     while(Tx1_Counter == TX1_BUFFER_SIZE);        
  110.         
  111.     //压入数据
  112.     Tx1_Buffer[Tx1_WriteIndex] = ch;
  113.     //发送缓冲区写计数器移动
  114.     Tx1_WriteIndex ++;
  115.     if( Tx1_WriteIndex >= TX1_BUFFER_SIZE )
  116.         {
  117.             //写指针移动到队列头部        
  118.                 Tx1_WriteIndex = 0;                                
  119.         }
  120.     //数据总数增加
  121.     Tx1_Counter++;
  122.         
  123.     //使能发送中断
  124.         USART_ITConfig(USART1,USART_IT_TXE,ENABLE);
  125.    
  126.         return Tx1_WriteIndex;        
  127. }
  128. /**
  129.   * @brief  返回发送队列中的字节数
  130.   * @param  无
  131.   * @retval 发送队列中的字节数
  132.   */
  133. uint8_t Get_Tx1BufCounter(void)
  134. {
  135.     return Tx1_Counter;
  136. }

  137. /**
  138.   * @brief  从接收队列中取出数据.
  139.   * @param  None
  140.   * @retval 被取出数据
  141.   */
  142. uint8_t Get_Rx1Item(void)
  143. {
  144.         uint8_t Rx1_Data;
  145.    
  146.         //等待,需要修改
  147.         while(Rx1_Counter == 0);
  148.    
  149.         //从队列中读取数据
  150.         Rx1_Data = Rx1_Buffer[Rx1_ReadIndex];
  151.     //接收缓冲区读指针移动
  152.         Rx1_ReadIndex ++;
  153.         if(Rx1_ReadIndex >= RX1_BUFFER_SIZE)
  154.         {
  155.                 Rx1_ReadIndex = 0;
  156.         }
  157.     //
  158.         Rx1_Counter --;

  159.         return Rx1_Data;        
  160. }

  161. /**
  162.   * @brief  返回接收队列中的字节数
  163.   * @param  无
  164.   * @retval 接收队列中的字节数
  165.   */
  166. uint8_t Get_Rx1BufCounter(void)
  167. {
  168.     return Rx1_Counter;
  169. }

  170. /**
  171.   * @brief  清空发送队列
  172.   * @param  无
  173.   * @retval 无
  174.   */
  175. void Clear_Tx1Buf(void)
  176. {
  177.     for(uint8_t i = 0 ; i < TX1_BUFFER_SIZE ; i++)
  178.     {
  179.         Tx1_Buffer = 0;
  180.     }
  181.     Tx1_Counter = 0;
  182. }
  183. /**
  184.   * @brief  清空接收队列
  185.   * @param  无
  186.   * @retval 无
  187.   */
  188. void Clear_Rx1Buf(void)
  189. {
  190.     for(uint8_t i = 0 ; i < RX1_BUFFER_SIZE ; i++)
  191.     {
  192.         Rx1_Buffer = 0;
  193.     }
  194.    
  195.     Rx1_Counter = 0;
  196. }

  197. /**
  198.   * @brief  USART1中断.
  199.   * @param  None
  200.   * @retval None
  201.   */
  202. void USART1_IRQHandler(void)
  203. {
  204.           uint8_t ch;
  205.         
  206.     //接收中断
  207.         if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
  208.           {
  209.                 //读取数据
  210.                 ch = USART_ReceiveData(USART1);               
  211.         
  212.         //清除接收中断标志位
  213.         //USART_ClearFlag(USART1,USART_FLAG_RX1NE);
  214.         //接收缓冲区数据个数递增
  215.                 Rx1_Counter++;        
  216.         
  217.                 //数据填入接收队列
  218.                 Rx1_Buffer[Rx1_WriteIndex] = ch;
  219.         
  220.                 Rx1_WriteIndex ++;
  221.                 if(Rx1_WriteIndex >= RX1_BUFFER_SIZE)
  222.                 {
  223.                         Rx1_WriteIndex = 0;
  224.                 }

  225.                 //队列溢出
  226.                 if(Rx1_Counter >= RX1_BUFFER_SIZE)
  227.                 {
  228.                         //数据作废,修改
  229.                         //Rx1_Counter = 0;
  230.                         //溢出标志置位
  231.                         Rx1_BufOverflow = 1;
  232.                 }

  233.           }
  234.    
  235.         //发送中断
  236.         if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  237.           {
  238.                 //清除接收中断标志位
  239.                 //USART_ClearFlag(USART1,USART_FLAG_TX1E);
  240.                 //存在未发送的数据
  241.                 if(Tx1_Counter > 0)
  242.                 {
  243.                         //发送数据
  244.                         USART_SendData(USART1, Tx1_Buffer[Tx1_ReadIndex]);
  245.             //发送数据总数递减
  246.                         Tx1_Counter --;
  247.                         Tx1_ReadIndex++;
  248.                         //回到缓冲区开头
  249.                         if(Tx1_ReadIndex >= TX1_BUFFER_SIZE)
  250.                         {
  251.                                 Tx1_ReadIndex = 0;
  252.                         }
  253.                 }
  254.         else
  255.         {
  256.             //无发送数据,关闭发送中断
  257.             USART_ITConfig(USART1,USART_IT_TXE,DISABLE);;  
  258.         }
  259.           }
  260. }


  261. int fputc(int ch, FILE * f)
  262. {
  263.     //通过串口发送数据  
  264.     Add_Tx1Item((uint8_t)ch);
  265.    
  266.     return ch;
  267. }


 楼主| sjg142729 发表于 2015-10-29 09:07 | 显示全部楼层
非常感谢两位
但没有stm8采集sht10的程序吗
sun1238898 发表于 2015-10-29 10:03 | 显示全部楼层
SHT10和SHT11的时序是一样的,只是精度不一样而已。楼主不要迟疑。
september7 发表于 2015-10-29 19:28 | 显示全部楼层
734774645 发表于 2015-10-28 17:31
楼上的发错了那个是SHT21,楼主要的是SHT11,我来发个例程。
----------------

赞一个!
734774645 发表于 2015-10-29 19:48 | 显示全部楼层
尤彼卡 发表于 2015-10-29 19:51 | 显示全部楼层
SHTxx系列单芯片传感器是一款含有已校准数字信号输出的温湿度复合传感器
有没有原理图呢
 楼主| sjg142729 发表于 2015-11-1 15:05 | 显示全部楼层
有没有寄存器版本的?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝

1

主题

3

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部