洛尘 发表于 2012-6-28 11:54:47

使用AT24c512的怎么模拟I2C

AT24c512要使用I2C,但是我没有用stm32默认的I2C接口的引脚,而是使用了其他的引脚,现在就是不知道还能不能使用他的固件库中的函数了,哪位大侠知道,请赐教

shuishou 发表于 2012-6-28 15:52:51

RE:使用AT24c512的怎么模拟I2C

可以模拟I2C,这是24C02的例子,供参考
*******************************************************************************
* File Name             : I2C_24c02_simulink.c
* Author                : Rasar Yao
* Date First Issued   : 04/26/2010
* Deion         : I2C_24c02_simulink_TEST
********************************************************************************/
#include "stm32f10x_lib.h"
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 Tx1_Buffer[] = "123456789abcdef";

/* Private variables ---------------------------------------------------------*/
static volatile ErrorStatus HSEStartUpStatus = SUCCESS;
void RCC_Configuration(void);
void I2C_GPIO_Config(void);
extern bool I2C_WriteByte(u8 SendByte, u16 WriteAddress, u8 DeviceAddress);
extern bool I2C_ReadByte(u8* pBuffer,   u8 length,   u16 ReadAddress,u8 DeviceAddress);
int main(void)
{
    RCC_Configuration();
I2C_GPIO_Config();
I2C_WriteByte(0x55, 0x30,0xA0) ;
I2C_ReadByte(Tx1_Buffer,   0x02,   0x30,0xA0);
while(1)
{
}
}

/*******************************************************************************
* Name: RCC_Configuration
* Deion    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
/* 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 GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO, ENABLE);
}
void I2C_GPIO_Config(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
/* Configure I2C1 pins: SCL and SDA */
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}

洛尘 发表于 2012-6-28 16:57:54

回复:使用AT24c512的怎么模拟I2C

怎么缺失两个函数主体吧
I2C_WriteByte(0x55, 0x30, 0xA0) ;
I2C_ReadByte(Tx1_Buffer, 0x02, 0x30, 0xA0);
是自己写的吧

shuishou 发表于 2012-6-28 22:00:23

RE:使用AT24c512的怎么模拟I2C

函数体是与其它单片机相同的
页: [1]
查看完整版本: 使用AT24c512的怎么模拟I2C