標(biāo)題:
stm32+cc1101通訊可用程序
[打印本頁]
作者:
a643727742
時間:
2018-9-7 15:32
標(biāo)題:
stm32+cc1101通訊可用程序
cc1101是一種915M、868M和433M無線通訊模塊,32程序例程如附件,實測可以
單片機(jī)源程序如下:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Version : V2.0.3
* Date : 09/22/2008
* Description : Main program body
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
//#include "platform_config.h"
#include "spi_cc1101.h"
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
#define FLASH_WriteAddress 0x000000
#define FLASH_ReadAddress FLASH_WriteAddress
#define FLASH_SectorToErase FLASH_WriteAddress
#define AT45DB161D_FLASH_ID 0x1F260000
#define BufferSize (countof(Tx_Buffer)-1)
#define ZB_LCD_POWER_PIN GPIO_Pin_0
/* Private macro -------------------------------------------------------------*/
#define countof(a) (sizeof(a) / sizeof(*(a)))
/* Private variables ---------------------------------------------------------*/
//u8 Tx_Buffer[] = "STM32F10x SPI Firmware Library Example: communication with an AT45DB161D SPI FLASH";
//u8 Index, Rx_Buffer[BufferSize];
volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = PASSED;
vu32 FLASH_ID = 0;
ErrorStatus HSEStartUpStatus;
/* Private functions ---------------------------------------------------------*/
TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void ZB_LCD_PowerCtrl_Init(void);
void ZB_LCD_PowerOn(void);
void ZB_LCD_PowerOff(void);
void led_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
debug();
#endif
ZB_LCD_PowerCtrl_Init();
ZB_LCD_PowerOn();
/* System clocks configuration */
RCC_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* GPIO configuration */
//GPIO_Configuration();
/* Initialize the SPI driver */
SPI_CC1101_Init();
led_init();
CC1101_Main();
}
/*******************************************************************************
* Function Name : RCC_Configuration
* Description : Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while (RCC_GetSYSCLKSource() != 0x08)
{}
}
/* Enable GPIO_LED clock */
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);
}
/*******************************************************************************
* Function Name : GPIO_Configuration
* Description : Configures the different GPIO ports.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
//GPIO_InitTypeDef GPIO_InitStructure;
/* Configure GPIO LED pin6 and pin7 as Output push-pull --------------------*/
/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);*/
}
void ZB_LCD_PowerCtrl_Init(void)
{
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
gpio_init.GPIO_Pin = ZB_LCD_POWER_PIN;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &gpio_init);
}
void ZB_LCD_PowerOn(void)
{
GPIO_SetBits(GPIOE, ZB_LCD_POWER_PIN);
}
void ZB_LCD_PowerOff(void)
{
GPIO_ResetBits(GPIOE, ZB_LCD_POWER_PIN);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
/*******************************************************************************
* Function Name : Buffercmp
* Description : Compares two buffers.
* Input : - pBuffer1, pBuffer2: buffers to be compared.
* : - BufferLength: buffer's length
* Output : None
* Return : PASSED: pBuffer1 identical to pBuffer2
* FAILED: pBuffer1 differs from pBuffer2
*******************************************************************************/
TestStatus Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return FAILED;
}
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
stm32_cc1101.rar
(2.02 MB, 下載次數(shù): 144)
2018-9-8 03:57 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
liuzhe0303
時間:
2019-11-7 09:02
好貼,有幫助
作者:
wanshaoying
時間:
2019-11-7 10:38
STM32F103C8T6可以用嗎?
作者:
mvwtest
時間:
2020-8-9 20:46
thanks 4 share
作者:
zhao850819
時間:
2021-1-6 10:13
好貼,感謝作者分享
作者:
mmloster001
時間:
2021-8-27 22:55
謝謝,可以用來參考開發(fā)CC113L
作者:
absflash
時間:
2021-9-3 14:09
堪稱神壇了,感覺常用代碼都能找到,隨手一百¥度就進(jìn)來了
作者:
xllin
時間:
2021-9-17 10:04
感謝作者分享,買了2片準(zhǔn)備試一下。
作者:
213333
時間:
2022-5-3 22:59
帖子不錯,就是不小心下載了2次 扣了10分
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1