可不可以直接用i2c向外面按照协议格式一直发数据,需要有什么方面的配置。为什么我的配置之后只能发送地址信息,然后就结束了。。。。。小白求帮助。
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/** @addtogroup Template_Project
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
sta
tic __IO uint32_t TimingDelay;
RCC_ClocksTypeDef RCC_Clocks;
__IO uint16_t sEEAddress = 0x44;
//__IO uint32_t sEETimeout = sEE_LONG_TIMEOUT;
__IO uint16_t sEEDataNum;
__IO uint32_t sEETimeout;
__IO uint32_t sEETrials = 0;
#define sEE_WRITE_ADDRESS1 0x00
#define sEE_READ_ADDRESS1 0x00
#define BUFFER_SIZE1 256
#define BUFFER_SIZE2 256
#define sEE_WRITE_ADDRESS2 (sEE_WRITE_ADDRESS1 + BUFFER_SIZE1)
#define sEE_READ_ADDRESS2 (sEE_READ_ADDRESS1 + BUFFER_SIZE1)
//状态变量
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
uint8_t senddata=0xa0;
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStruct;
// 配置I2C始终资源
RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
//GPIO使能
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
//IIC使能
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
//GPIO管脚配置
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/* I2C configuration */
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStruct.I2C_DigitalFilter = 0x00;
I2C_InitStruct.I2C_OwnAddress1 =0x00;
// I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_Timing =0x00210507;//100Kbits
I2C_Init(I2C1, &I2C_InitStruct);
//I2C_SMBusAlertCmd(I2C1,ENABLE);
I2C_Cmd(I2C1, ENABLE);
while(1)
{
I2C_TransferHandling(I2C1, sEEAddress, 2, I2C_Reload_Mode, I2C_Generate_Start_Write);
I2C_SendData(I2C1,senddata);
}
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 10 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
不连从设备你怎么发数据
一周热门 更多>