找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5556|回复: 8
收起左侧

STM32+ADS1256数据采集卡程序源码

[复制链接]
ID:402226 发表于 2018-11-21 17:05 | 显示全部楼层 |阅读模式
STM32采集卡程序,需要自取
STM32F103C8T6与ADS1256连线说明   
F103C8T6开发板GPIOB11    ---    ADS1256板子RESET   相连
F103C8T6开发板GPIOB10    ---    ADS1256板子 DRDY  相连
F103C8T6开发板GPIOB12    ---    ADS1256板子CS   相连
F103C8T6开发板GPIOB13    ---    ADS1256板子SCLK  相连
F103C8T6开发板GPIOB14    ---    ADS1256板子DOUT  相连
F103C8T6开发板GPIOB15    ---    ADS1256板子DIN  相连
F103C8T6开发板GND               ---    ADS1256板子DGND 相连

实际测试连线图
0.png

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "stm32_eval.h"
  3. #include "flash.h"
  4. #include "delay.h"
  5. #include "ADS1256.h"
  6. #include <stdio.h>

  7. /** @addtogroup STM32F10x_StdPeriph_Examples
  8.   * @{
  9.   */

  10. /** @addtogroup USART_Printf
  11.   * @{
  12.   */

  13. /* Private typedef -----------------------------------------------------------*/
  14. /* Private define ------------------------------------------------------------*/
  15. /* Private macro -------------------------------------------------------------*/


  16. /* Private variables ---------------------------------------------------------*/
  17. /* Values magic to the Board keys */
  18. #define  NOKEY  0
  19. #define  KEY1   1
  20. #define  KEY2   2
  21. #define  KEY3   3
  22. #define  KEY4   4


  23. unsigned char data[16];




  24. /* Private function prototypes -----------------------------------------------*/

  25. #ifdef __GNUC__
  26.   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  27.      set to 'Yes') calls __io_putchar() */
  28.   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  29. #else
  30.   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  31. #endif /* __GNUC__ */
  32.   
  33.   
  34. /* Private functions ---------------------------------------------------------*/

  35. void Init_UART2()
  36. {
  37.         USART_InitTypeDef USART_InitStructure;
  38.         /* USARTx configured as follow:
  39.         - BaudRate = 115200 baud  
  40.         - Word Length = 8 Bits
  41.         - One Stop Bit
  42.         - No parity
  43.         - Hardware flow control disabled (RTS and CTS signals)
  44.         - Receive and transmit enabled
  45.   */       
  46.         USART_InitStructure.USART_BaudRate = 9600;
  47.           USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  48.           USART_InitStructure.USART_StopBits = USART_StopBits_1;
  49.           USART_InitStructure.USART_Parity = USART_Parity_No;
  50.           USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  51.           USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  52.           STM_EVAL_COMInit(COM1, &USART_InitStructure);
  53. }


  54. /**
  55.   * @brief  Main program
  56.   * @param  None
  57.   * @retval None
  58.   */
  59. int main(void)
  60. {
  61.         unsigned char i=0;
  62.         long ulResult;
  63.         long double ldVolutage;

  64.         Init_UART2();

  65.         Init_ADS1256_GPIO(); //初始化ADS1256 GPIO管脚

  66.         Delay(0x1ffFF);
  67.         GPIO_SetBits(GPIOB, GPIO_Pin_11 );  
  68.         ADS1256_Init();

  69.         while(1)
  70.         {       
  71.                 for(i = 0;i < 8;i++)
  72.                 {
  73.                          ulResult = ADS_sum( (i << 4) | ADS1256_MUXN_AINCOM);       
  74.                         //ulResult = ADS_sum( ADS1256_MUXP_AIN0 | ADS1256_MUXN_AINCOM);       
  75.                         if( ulResult & 0x800000 )
  76.                         {
  77.                                  ulResult = ~(unsigned long)ulResult;
  78.                                 ulResult &= 0x7fffff;
  79.                                 ulResult += 1;
  80.                                 ulResult = -ulResult;
  81.                         }
  82.                
  83.                         ldVolutage = (long double)ulResult*0.59604644775390625;

  84.                         printf("第%d通道:",(i & 0x07)?(i & 0x07) - 1:7);
  85.                         printf("%lf",ldVolutage);         //double
  86.                         printf("uV\r");
  87.                

  88.                         //printf("%x",(unsigned long)ulResult);//16
  89.                         Delay(0x3fFFF);
  90.                 }
  91.                                 printf("\n");
  92. //                        printf("123456\n");
  93.         }
  94.                
  95. }

  96. /**
  97.   * @brief  Retargets the C library printf function to the USART.
  98.   * @param  None
  99.   * @retval None
  100.   */
  101. PUTCHAR_PROTOTYPE
  102. {
  103.   /* Place your implementation of fputc here */
  104.   /* e.g. write a character to the USART */
  105.   USART_SendData(EVAL_COM1, (uint8_t) ch);

  106.   /* Loop until the end of transmission */
  107.   while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  108.   {}

  109.   return ch;
  110. }


  111. #ifdef  USE_FULL_ASSERT

  112. /**
  113.   * @brief  Reports the name of the source file and the source line number
  114.   *         where the assert_param error has occurred.
  115.   * @param  file: pointer to the source file name
  116.   * @param  line: assert_param error line source number
  117.   * @retval None
  118.   */
  119. void assert_failed(uint8_t* file, uint32_t line)
  120. {
  121.   /* User can add his own implementation to report the file name and line number,
  122.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  123.   /* Infinite loop */
  124.   while (1)
  125.   {
  126.   }
  127. }
  128. #endif

  129. /**
  130.   * @}
  131.   */

  132. /**
  133.   * @}
  134.   */

  135. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
STM32F103C8T6测试OK.rar (5.14 MB, 下载次数: 179)
回复

使用道具 举报

ID:387410 发表于 2019-3-22 09:33 | 显示全部楼层
参考一下,谢谢
回复

使用道具 举报

ID:98985 发表于 2019-4-17 13:10 | 显示全部楼层
参考学习,多谢
回复

使用道具 举报

ID:520450 发表于 2019-4-24 14:38 | 显示全部楼层
这个资料挺好的
回复

使用道具 举报

ID:41656 发表于 2019-7-13 12:11 | 显示全部楼层
这种串口的低速还行  高速就不好使了吧
回复

使用道具 举报

ID:588192 发表于 2019-7-26 13:00 | 显示全部楼层
这个程序为什么换成STM32f10xZET就用不了
回复

使用道具 举报

ID:588192 发表于 2019-7-27 11:35 | 显示全部楼层
不能用的程序能不能注明一下仅供参考
回复

使用道具 举报

ID:93206 发表于 2020-5-11 14:45 | 显示全部楼层
需要用这个
回复

使用道具 举报

ID:672518 发表于 2020-5-20 13:41 | 显示全部楼层
谢谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表