cc1101是一種915M、868M和433M無線通訊模塊,32程序例程如附件,實測可以
單片機源程序如下:
- /******************** (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黑下載附件…………
復制代碼
所有資料51hei提供下載:
stm32_cc1101.rar
(2.02 MB, 下載次數: 144)
2018-9-8 03:57 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|