找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 6895|回復(fù): 8
打印 上一主題 下一主題
收起左側(cè)

STM32+ADS1256數(shù)據(jù)采集卡程序源碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:402226 發(fā)表于 2018-11-21 17:05 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
STM32采集卡程序,需要自取
STM32F103C8T6與ADS1256連線說明   
F103C8T6開發(fā)板GPIOB11    ---    ADS1256板子RESET   相連
F103C8T6開發(fā)板GPIOB10    ---    ADS1256板子 DRDY  相連
F103C8T6開發(fā)板GPIOB12    ---    ADS1256板子CS   相連
F103C8T6開發(fā)板GPIOB13    ---    ADS1256板子SCLK  相連
F103C8T6開發(fā)板GPIOB14    ---    ADS1256板子DOUT  相連
F103C8T6開發(fā)板GPIOB15    ---    ADS1256板子DIN  相連
F103C8T6開發(fā)板GND               ---    ADS1256板子DGND 相連

實(shí)際測(cè)試連線圖


單片機(jī)源程序如下:
  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****/
復(fù)制代碼

所有資料51hei提供下載:
STM32F103C8T6測(cè)試OK.rar (5.14 MB, 下載次數(shù): 185)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:387410 發(fā)表于 2019-3-22 09:33 | 只看該作者
參考一下,謝謝
回復(fù)

使用道具 舉報(bào)

板凳
ID:98985 發(fā)表于 2019-4-17 13:10 | 只看該作者
參考學(xué)習(xí),多謝
回復(fù)

使用道具 舉報(bào)

地板
ID:520450 發(fā)表于 2019-4-24 14:38 | 只看該作者
這個(gè)資料挺好的
回復(fù)

使用道具 舉報(bào)

5#
ID:41656 發(fā)表于 2019-7-13 12:11 | 只看該作者
這種串口的低速還行  高速就不好使了吧
回復(fù)

使用道具 舉報(bào)

6#
ID:588192 發(fā)表于 2019-7-26 13:00 | 只看該作者
這個(gè)程序?yàn)槭裁磽Q成STM32f10xZET就用不了
回復(fù)

使用道具 舉報(bào)

7#
ID:588192 發(fā)表于 2019-7-27 11:35 | 只看該作者
不能用的程序能不能注明一下僅供參考
回復(fù)

使用道具 舉報(bào)

8#
ID:93206 發(fā)表于 2020-5-11 14:45 | 只看該作者
需要用這個(gè)
回復(fù)

使用道具 舉報(bào)

9#
ID:672518 發(fā)表于 2020-5-20 13:41 | 只看該作者
謝謝分享
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表