资源简介
实现用IO口模拟I2C slave程序,采用中断处理;
代码片段和文件信息
/***********************************************************************
Copyright 2008 Si-Power Co.Ltd. All Right reserved
************************************************************************
* IIC SLAVE Function Definitions
* gpio simulate i2c
* 适合在i2c时钟为10k情形,最大可为50K,但此时不能把写寄存器的操作放到中断
* 里面处理,应放到外面处理,因为写CODE寄存器的操作时间比较长;
* $Id: i2c_io.cv 1.0 2012/08/13 15:13:30 liu Exp $
***********************************************************************/
#include “glb_df.h“
#include “types.h“
#include “common.h“
#include “sys_ctl/sys_ctl.h“
//#include “apb_timer/apb_timer.h“
#include “crt.h“
#include “gpio/sys_gpio.h“
#include “i2c_io.h“
#ifdef UART_DEBUG
//#define UART_DEBUG_KEY
#ifdef UART_DEBUG_KEY
static char c = ‘I‘;
#endif
#if 0
#define IDBG(x) x
#else
#define IDBG(x)
#endif
#else
#define IDBG(x)
#endif
extern void sys_iomux(int ioidx);
#ifdef SIMULUTE_I2C_USED
//add by rolly
EN_I2C_STATE i2c_state = NONE_STATE;
U8 i2c_address_buf = 0;
U8 i2c_address = 0;
U8 rx_count = 0;
U8 receve_dat_buf = 0;
U8 send_dat_buf = 0;
U8 send_dat_temp = 0;
U8 receve_dat = 0;
BOOL write_finish =FALSE;
BOOL read_finish = FALSE;
//BOOL read_finish = FALSE;
BOOL new_data_flag = FALSE;
BOOL new_addr_flag = FALSE;
//U8 rx_count_flag;
U8 interrup_count;
uint16 rece_data_buf[150];
U8 buf_count = 0;
U8 start_count = 0;
U8 read_count =0;
U8 stop_count = 0;
U8 addr_buf[10];
#define SYS_CODEC_base (0XFF80)
__attribute__ ((section(“.ISR\“ax\““)))
void i2c_sda_isr()
{
uint32 reg32_val;
if(sys_gpiord(I2C_SCL_IO) == GPIO_HIGH)
{
i2c_state = START_STATE;
rx_count = 0;
//start_count++;
/*SysReadAMBAReg((SYS_GPIO_IEN)reg32_val); //disable interrupt
reg32_val &= ~(1L < SysWriteAMBAReg((SYS_GPIO_IEN)reg32_val);*/
}
/*else
{
i2c_state = STOP_STATE;
stop_count++;
}
if( (sys_gpiord(I2C_SCL_IO) == GPIO_HIGH) && (i2c_state == NONE_STATE) )
{
//myptf(“i2c start!\r\n“);
SysReadAMBAReg((SYS_GPIO_IEN)reg32_val); //disable interrupt
reg32_val &= ~(1L < SysWriteAMBAReg((SYS_GPIO_IEN)reg32_val);
}
if(sys_gpiord(I2C_SCL_IO) == GPIO_HIGH)
{
//myptf(“i2c stop!\r\n“);
i2c_state = STOP_STATE;
SysReadAMBAReg((SYS_GPIO_IEV)reg32_val); //Falling edge-trigger
reg32_val &= ~(1L < SysWriteAMBAReg((SYS_GPIO_IEV)reg32_val);
}*/
}
/*void i2c_sda_isr1()//falling inerrupt
{
uint32 reg32_val;
if (sys_gpiord(I2C_SCL_IO) == GPIO_HIGH )
{
//myptf(“i2c start!\r\n“);
i2c_state = START_STATE;
/*SysReadAMBAReg((SYS_GPIO_IEV)reg32_val); //Rising edge-trigger
reg32_val |= (1L < SysWriteAMBAReg((SYS_GPIO_IEV)reg32_val);
}
}*/
void i2c_scl_isr1() //下降沿
{
switch ( i2c_state )
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11492 2005-08-14 18:17 模拟I2C\i2c_io.c
文件 752 2005-08-14 16:07 模拟I2C\i2c_io.h
目录 0 2005-08-24 10:11 模拟I2C\
- 上一篇:迪兰恒进R9 270 2GB 原版BIOS
- 下一篇:TDA7498PCB
评论
共有 条评论