PRIVATE void vSBReadIIC uint8 u8SlaveAddress uint8 u8Address uint8 pau

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
PRIVATE void vSBReadIIC(uint8 u8SlaveAddress, uint8 u8Address, uint8 *pau8ReadBuffer, int16 i16Length)
{
uint8 i=0;
uint16 u16ReadLength;
if(i16Length < 0x01)
{
return;
}
u16ReadLength = i16Length;
vPrintf("Start read\n");
/* set slave address */
//u8SlaveAddress = u8SlaveAddress << 1;
vAHI_SiWriteSlaveAddr(u8SlaveAddress,FALSE);
vAHI_SiSetCmdReg(E_AHI_SI_START_BIT,
E_AHI_SI_NO_STOP_BIT,
E_AHI_SI_NO_SLAVE_READ,
E_AHI_SI_SLAVE_WRITE,
E_AHI_SI_SEND_ACK,
E_AHI_SI_NO_IRQ_ACK);
while(bAHI_SiPollTransferInProgress()); /* wait while busy */
/* check to see if anyone else has taken the bus */
/*if(bAHI_SiPollRxNack())
{
vDebug("Error 1\n");
return;
}*/
if(bAHI_SiPollArbitrationLost())
{
vPrintf("Error 2\n");
return;
}
vPrintf("Write addr\n");
vAHI_SiWriteData8(u8Address | 0x80); /* address to start read from */
vAHI_SiSetCmdReg(E_AHI_SI_NO_START_BIT,
E_AHI_SI_NO_STOP_BIT,
E_AHI_SI_NO_SLAVE_READ,
E_AHI_SI_SLAVE_WRITE,
E_AHI_SI_SEND_ACK,
E_AHI_SI_NO_IRQ_ACK);
while(bAHI_SiPollTransferInProgress()); /* wait while busy */
vPrintf("Switch to read\n");
//u8SlaveAddress = u8SlaveAddress | 0x01;
vAHI_SiWriteSlaveAddr(u8SlaveAddress,TRUE);
//vAHI_SiWriteSlaveAddr(u8Address,TRUE);
vAHI_SiSetCmdReg(E_AHI_SI_START_BIT,
E_AHI_SI_NO_STOP_BIT,
E_AHI_SI_SLAVE_READ,
E_AHI_SI_NO_SLAVE_WRITE,
E_AHI_SI_SEND_ACK,
E_AHI_SI_NO_IRQ_ACK);
//
while(bAHI_SiPollTransferInProgress()); /* wait while busy */
// vPrintf("Before reading\n");
/* now we can start reading data back from the eeprom */
while(u16ReadLength > 0x00)
{
if(u16ReadLength < 2) /* is it the last byte */
{
vAHI_SiSetCmdReg(E_AHI_SI_NO_START_BIT,
E_AHI_SI_STOP_BIT,
E_AHI_SI_SLAVE_READ,
E_AHI_SI_NO_SLAVE_WRITE,
E_AHI_SI_SEND_NACK,
E_AHI_SI_NO_IRQ_ACK);
}
else
{
vAHI_SiSetCmdReg(E_AHI_SI_NO_START_BIT,
E_AHI_SI_NO_STOP_BIT,
E_AHI_SI_SLAVE_READ,
E_AHI_SI_NO_SLAVE_WRITE,
E_AHI_SI_SEND_ACK,
E_AHI_SI_NO_IRQ_ACK);
}
while(bAHI_SiPollTransferInProgress()); /* wait while busy */
pau8ReadBuffer[i++] = u8AHI_SiReadData8();
u16ReadLength--;
}
vPrintf("read complete\n");
}