STM32使用模拟IIC操作EEPROM
//该函数改写原来的函数 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************/
STM32模拟IIC操作EEPRO 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)