微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32使用模拟IIC操作EEPROM

STM32使用模拟IIC操作EEPROM

时间:12-03 来源:互联网 点击:

//该函数改写原来的函数 2016-09-16 by wit_yuan

unsigned char read_eeprom_status(unsigned char c_slave_address7bit)

{

unsigned int i = 0;

int i_ret = 0;

do

{

IIC_Start();

IIC_Send_Byte(c_slave_address7bit < 1);

i_ret = IIC_Wait_Ack();

i++;

if(i >= 10000)

{

IIC_Stop();

return 1;//表示无响应

}

}while(i_ret);

IIC_Stop();

return 0;//表示操作序列结束

}



主测试程序main.c:

/******************** (C) COPYRIGHT 2015 **************************
* 文件名 :main.c
* 描述 :

**********************************************************************************/
#include "stm32f10x.h"
#include "usart1.h"
#include "i2c.h"

static void delay(int time)
{
int i = 0 ,j = 0;
for(i = 0 ; i < 5 ; i ++)
for(j = 0 ; j < time ; j ++)
;
}

unsigned char g_c_continue_read_array[256];

unsigned char g_c_continue_write[256];

/*
* 函数名:main
* 描述 :主函数
* 输入 :无
* 输出 :无
*/
int main(void)
{
unsigned int i;
unsigned char value;
/* USART1 config 9600 8-N-1 */
USART1_Config();

printf("--------app run-----------\n");

IIC_Init();

//memset(g_c_continue_write,0x32,256);

printf("write:\n");
for(i = 0 ; i < 16 ; i ++)
{
//printf("%0x ",g_c_continue_write[i]);
g_c_continue_write[i] = i;
}
printf("\n");

eeprom_continue_write(EEPROM_SLAVE_ADDRESS,0,g_c_continue_write,16);

value = read_eeprom_status(EEPROM_SLAVE_ADDRESS);
printf("\n status : %d\n",value);

//printf("status = %d\n",read_eeprom_status());

eeprom_continue_read(EEPROM_SLAVE_ADDRESS,0,g_c_continue_read_array,16);

printf("read:\n");
for(i = 0 ; i < 16 ; i ++)
{
printf("%0x ",g_c_continue_read_array[i]);
}
printf("\n");

value = eeprom_read(EEPROM_SLAVE_ADDRESS,0x15);
printf("value = 0x%0x\n",value);

printf("write:\n");
eeprom_write(EEPROM_SLAVE_ADDRESS,0x01,0x25);
value = read_eeprom_status(EEPROM_SLAVE_ADDRESS);
value = eeprom_read(EEPROM_SLAVE_ADDRESS,0x01);
printf("value = 0x%0x\n",value);

for(;;)
{

}
}
/******************* (C) COPYRIGHT 2016 *****END OF FILE************/


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top