|
#include
#include
#include
typedef unsigned char uint8_t;
typedef struct
{
char chip;
unsigned int addr;
int addr_length;
void *buffer;
unsigned int length;
} twi_package_t;
unsigned char i2c_addresses[] =
{
0x4a,
0x4b,
0x24,
0x25,
};
int twi_master_read(const twi_package_t *package)
{
unsigned char TwiStatus;
unsigned char * TwiData;
unsigned char sla;
unsigned char r_reg;
unsigned int len;
sla = package->chip;//把0x4b 传给sla 可是在avr studio中 总是出错 这个地方传不过来
r_reg = package->addr;
TwiData = package->buffer;
len = package->length;
return sla;
}
unsigned char address_slave(void)
{
uint8_t i;
uint8_t status;
static uint8_t *rxtmp;
twi_package_t packet;
packet.chip = i2c_addresses[1];//把0x4b给chip
packet.addr = 0;
packet.addr_length = 0;
packet.buffer = (void*) rxtmp;
packet.length = 1;
status = twi_master_read(&packet);//通过结构体变量完成数据传递
return status;
}
int main()
{
unsigned char i;
i =address_slave();
printf("%x\n",i);
return 0;
}
这段代码在vc++ 6.0中调试没问题 ox4b 可以成功的通过chip传给sla 可是在avr studio里软件仿真时就不行 sla接不到正确的数 不知道 为什么是不是 编译器的问题 有高手给解答下 谢谢
|
|