找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4500|回复: 8
打印 上一主题 下一主题
收起左侧

stm32+cc1101通讯可用程序

  [复制链接]
跳转到指定楼层
楼主
ID:395041 发表于 2018-9-7 15:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
cc1101是一种915M、868M和433M无线通讯模块,32程序例程如附件,实测可以

单片机源程序如下:
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name          : main.c
  3. * Author             : MCD Application Team
  4. * Version            : V2.0.3
  5. * Date               : 09/22/2008
  6. * Description        : Main program body
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/

  15. /* Includes ------------------------------------------------------------------*/
  16. //#include "platform_config.h"
  17. #include "spi_cc1101.h"

  18. /* Local includes ------------------------------------------------------------*/
  19. /* Private typedef -----------------------------------------------------------*/
  20. typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;

  21. /* Private define ------------------------------------------------------------*/
  22. #define  FLASH_WriteAddress     0x000000
  23. #define  FLASH_ReadAddress      FLASH_WriteAddress
  24. #define  FLASH_SectorToErase    FLASH_WriteAddress
  25. #define  AT45DB161D_FLASH_ID    0x1F260000
  26. #define  BufferSize (countof(Tx_Buffer)-1)

  27. #define  ZB_LCD_POWER_PIN                GPIO_Pin_0

  28. /* Private macro -------------------------------------------------------------*/
  29. #define countof(a) (sizeof(a) / sizeof(*(a)))

  30. /* Private variables ---------------------------------------------------------*/
  31. //u8 Tx_Buffer[] = "STM32F10x SPI Firmware Library Example: communication with an AT45DB161D SPI FLASH";
  32. //u8 Index, Rx_Buffer[BufferSize];
  33. volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = PASSED;
  34. vu32 FLASH_ID = 0;
  35. ErrorStatus HSEStartUpStatus;

  36. /* Private functions ---------------------------------------------------------*/
  37. TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);
  38. void RCC_Configuration(void);
  39. void GPIO_Configuration(void);
  40. void NVIC_Configuration(void);

  41. void ZB_LCD_PowerCtrl_Init(void);
  42. void ZB_LCD_PowerOn(void);
  43. void ZB_LCD_PowerOff(void);

  44. void led_init(void)
  45. {
  46.         GPIO_InitTypeDef GPIO_InitStructure;
  47.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
  48.        
  49.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  50.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  51.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  52.         GPIO_Init(GPIOC, &GPIO_InitStructure);
  53. }

  54. /*******************************************************************************
  55. * Function Name  : main
  56. * Description    : Main program
  57. * Input          : None
  58. * Output         : None
  59. * Return         : None
  60. *******************************************************************************/
  61. int main(void)
  62. {
  63. #ifdef DEBUG
  64.   debug();
  65. #endif
  66.   ZB_LCD_PowerCtrl_Init();
  67.   ZB_LCD_PowerOn();

  68.   /* System clocks configuration */
  69.   RCC_Configuration();

  70.   /* NVIC configuration */
  71.   NVIC_Configuration();

  72.   /* GPIO configuration */
  73.   //GPIO_Configuration();

  74.   /* Initialize the SPI driver */
  75.   SPI_CC1101_Init();
  76.   led_init();
  77.   CC1101_Main();  

  78. }

  79. /*******************************************************************************
  80. * Function Name  : RCC_Configuration
  81. * Description    : Configures the different system clocks.
  82. * Input          : None
  83. * Output         : None
  84. * Return         : None
  85. *******************************************************************************/
  86. void RCC_Configuration(void)
  87. {
  88.   /* RCC system reset(for debug purpose) */
  89.   RCC_DeInit();

  90.   /* Enable HSE */
  91.   RCC_HSEConfig(RCC_HSE_ON);

  92.   /* Wait till HSE is ready */
  93.   HSEStartUpStatus = RCC_WaitForHSEStartUp();

  94.   if (HSEStartUpStatus == SUCCESS)
  95.   {
  96.     /* Enable Prefetch Buffer */
  97.     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  98.     /* Flash 2 wait state */
  99.     FLASH_SetLatency(FLASH_Latency_2);

  100.     /* HCLK = SYSCLK */
  101.     RCC_HCLKConfig(RCC_SYSCLK_Div1);

  102.     /* PCLK2 = HCLK */
  103.     RCC_PCLK2Config(RCC_HCLK_Div1);

  104.     /* PCLK1 = HCLK/2 */
  105.     RCC_PCLK1Config(RCC_HCLK_Div2);

  106.     /* PLLCLK = 8MHz * 9 = 72 MHz */
  107.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

  108.     /* Enable PLL */
  109.     RCC_PLLCmd(ENABLE);

  110.     /* Wait till PLL is ready */
  111.     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  112.     {}

  113.     /* Select PLL as system clock source */
  114.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  115.     /* Wait till PLL is used as system clock source */
  116.     while (RCC_GetSYSCLKSource() != 0x08)
  117.     {}
  118.   }

  119.   /* Enable GPIO_LED clock */
  120.   //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);
  121. }

  122. /*******************************************************************************
  123. * Function Name  : GPIO_Configuration
  124. * Description    : Configures the different GPIO ports.
  125. * Input          : None
  126. * Output         : None
  127. * Return         : None
  128. *******************************************************************************/
  129. void GPIO_Configuration(void)
  130. {
  131.   //GPIO_InitTypeDef GPIO_InitStructure;

  132.   /* Configure GPIO LED pin6 and pin7 as Output push-pull --------------------*/
  133.   /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  134.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  135.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  136.   GPIO_Init(GPIO_LED, &GPIO_InitStructure);*/
  137. }

  138. void ZB_LCD_PowerCtrl_Init(void)
  139. {
  140.         GPIO_InitTypeDef  gpio_init;
  141.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
  142.         gpio_init.GPIO_Pin   = ZB_LCD_POWER_PIN;
  143.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  144.     gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
  145.     GPIO_Init(GPIOE, &gpio_init);

  146. }

  147. void ZB_LCD_PowerOn(void)
  148. {
  149. GPIO_SetBits(GPIOE, ZB_LCD_POWER_PIN);
  150. }

  151. void ZB_LCD_PowerOff(void)
  152. {
  153. GPIO_ResetBits(GPIOE, ZB_LCD_POWER_PIN);
  154. }

  155. /*******************************************************************************
  156. * Function Name  : NVIC_Configuration
  157. * Description    : Configures Vector Table base location.
  158. * Input          : None
  159. * Output         : None
  160. * Return         : None
  161. *******************************************************************************/
  162. void NVIC_Configuration(void)
  163. {
  164. #ifdef  VECT_TAB_RAM
  165.   /* Set the Vector Table base location at 0x20000000 */
  166.   NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  167. #else  /* VECT_TAB_FLASH  */
  168.   /* Set the Vector Table base location at 0x08000000 */
  169.   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  170. #endif
  171. }

  172. /*******************************************************************************
  173. * Function Name  : Buffercmp
  174. * Description    : Compares two buffers.
  175. * Input          : - pBuffer1, pBuffer2: buffers to be compared.
  176. *                : - BufferLength: buffer's length
  177. * Output         : None
  178. * Return         : PASSED: pBuffer1 identical to pBuffer2
  179. *                  FAILED: pBuffer1 differs from pBuffer2
  180. *******************************************************************************/
  181. TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength)
  182. {
  183.   while (BufferLength--)
  184.   {
  185.     if (*pBuffer1 != *pBuffer2)
  186.     {
  187.       return FAILED;
  188.     }

  189. ……………………

  190. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
stm32_cc1101.rar (2.02 MB, 下载次数: 144)



评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:472396 发表于 2019-11-7 09:02 | 只看该作者
好贴,有帮助
回复

使用道具 举报

板凳
ID:525122 发表于 2019-11-7 10:38 | 只看该作者
STM32F103C8T6可以用吗?
回复

使用道具 举报

地板
ID:781556 发表于 2020-8-9 20:46 | 只看该作者
thanks 4 share
回复

使用道具 举报

5#
ID:162154 发表于 2021-1-6 10:13 | 只看该作者
好贴,感谢作者分享
回复

使用道具 举报

6#
ID:398504 发表于 2021-8-27 22:55 | 只看该作者
谢谢,可以用来参考开发CC113L
回复

使用道具 举报

7#
ID:84495 发表于 2021-9-3 14:09 | 只看该作者
堪称神坛了,感觉常用代码都能找到,随手一百¥度就进来了
回复

使用道具 举报

8#
ID:187802 发表于 2021-9-17 10:04 | 只看该作者
感谢作者分享,买了2片准备试一下。
回复

使用道具 举报

9#
ID:160726 发表于 2022-5-3 22:59 | 只看该作者
帖子不错,就是不小心下载了2次 扣了10分
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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