i2c микросхема работает не стабильно.
переписал код с использованием fifo не помогло возможно вернусь к этому позже, возможно это дефект микросхемы
This commit is contained in:
parent
6744f8f648
commit
68f6585f9a
@ -87,6 +87,7 @@ uint32_t InCommand,InAddr,InData;
|
||||
// IPC ISR for Flag 1
|
||||
// C28x core sends data with message queue using Flag 0
|
||||
//
|
||||
uint16_t offset = 0;
|
||||
|
||||
void FillBuff1(void)
|
||||
{
|
||||
@ -95,10 +96,10 @@ void FillBuff1(void)
|
||||
|
||||
for(i=0; i < 2048; i++)
|
||||
{
|
||||
j = i & 0x7F;
|
||||
|
||||
j = (i+offset) & 0x7F;
|
||||
a = (2*j<<8);
|
||||
b = (2*j+1);
|
||||
//Buffer = (uint16_t *)(CMTOCPU1MSGRAM0_BASE+2*i);
|
||||
Buffer[i] = a+b;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ void main(void)
|
||||
asm (" NOP");
|
||||
ipc_run();
|
||||
#ifdef CPU1
|
||||
ExtEEPROM_run();
|
||||
frmmstr_run();
|
||||
// ExtEEPROM_run();
|
||||
// frmmstr_run();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,16 @@
|
||||
volatile uint16_t SlaveAdr = I2C_SLAVE_ADDRESS;
|
||||
uint16_t BufferZD24C02A[17];
|
||||
|
||||
uint16_t ZD24C02A_write_16(uint16_t Addr, uint16_t * Array, uint16_t quant)// ìîæåò ïèñàòü î÷åðåäÿìè ïî 16 áàéò
|
||||
uint16_t ZD24C02A_write_8(uint16_t Addr, uint16_t * Array, uint16_t quant)// ìîæåò ïèñàòü î÷åðåäÿìè ïî 16 áàéò
|
||||
{
|
||||
if(I2CWrite(SlaveAdr, Addr, quant, true, Array)) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
uint16_t ZD24C02A_read_16(uint16_t Addr, uint16_t * Array, uint16_t quant)
|
||||
uint16_t ZD24C02A_read_8(uint16_t Addr, uint16_t * Array, uint16_t quant)
|
||||
{
|
||||
|
||||
if(I2CWrite(SlaveAdr, Addr, 0, false, Array)) return 1;
|
||||
// if(I2CWrite(SlaveAdr, Addr, 0, false, Array)) return 1;
|
||||
if(I2CRead(SlaveAdr, quant, true, Array)) return 1;
|
||||
else return 0;
|
||||
}
|
||||
@ -40,24 +40,24 @@ uint16_t ZD24C02A_write(uint32_t Addr, uint16_t quant, uint16_t * write_data)
|
||||
{
|
||||
|
||||
uint32_t i=0;
|
||||
uint16_t addr_write_data[16];
|
||||
uint16_t addr_write_data[8];
|
||||
uint32_t Addressfull8bit;
|
||||
|
||||
if(quant > 8)
|
||||
if(quant > 4)
|
||||
{
|
||||
for(i = 0; i < (quant-8); i += 8)
|
||||
for(i = 0; i < (quant-4); i += 4)
|
||||
{
|
||||
copy16_to_8(write_data, addr_write_data, 8);
|
||||
copy16_to_8(write_data, addr_write_data, 4);
|
||||
Addressfull8bit = Addr+2*i;
|
||||
if( ZD24C02A_write_16(Addressfull8bit, addr_write_data, 16)) return 1;
|
||||
write_data += 8;
|
||||
if( ZD24C02A_write_8(Addressfull8bit, addr_write_data, 8)) return 1;
|
||||
write_data += 4;
|
||||
}
|
||||
}
|
||||
if(i < quant)
|
||||
{
|
||||
copy16_to_8(write_data, addr_write_data, (quant - i));
|
||||
Addressfull8bit = Addr+2*i;
|
||||
if( ZD24C02A_write_16(Addressfull8bit, addr_write_data, 2*(quant - i))) return 1;
|
||||
if( ZD24C02A_write_8(Addressfull8bit, addr_write_data, 2*(quant - i))) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -68,23 +68,23 @@ uint16_t ZD24C02A_read(uint32_t Addr, uint16_t quant16, uint16_t * read_data)
|
||||
uint32_t Addressfull8bit;
|
||||
uint16_t addr_read_data[8];
|
||||
|
||||
if(quant16 > 8)
|
||||
if(quant16 > 4)
|
||||
{
|
||||
for(i = 0; i < (quant16-8); i += 8)
|
||||
for(i = 0; i < (quant16-4); i += 4)
|
||||
{
|
||||
Addressfull8bit = Addr+2*i;
|
||||
if( ZD24C02A_read_16(Addr+i, addr_read_data, 16)) return 1;
|
||||
copy8_to_16(addr_read_data, read_data, 8);
|
||||
read_data+=8;
|
||||
if( ZD24C02A_read_8(Addr+i, addr_read_data, 8)) return 1;
|
||||
copy8_to_16(addr_read_data, read_data, 4);
|
||||
read_data+=4;
|
||||
}
|
||||
}
|
||||
if(i < quant16)
|
||||
{
|
||||
Addressfull8bit = Addr+2*i;
|
||||
if( ZD24C02A_read_16(Addressfull8bit, addr_read_data, 2*(quant16 - i))) return 1;
|
||||
if( ZD24C02A_read_8(Addressfull8bit, addr_read_data, 2*(quant16 - i))) return 1;
|
||||
copy8_to_16(addr_read_data, read_data, (quant16 - i));
|
||||
}
|
||||
else return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t ZD24C02A_verify(uint32_t Addr, uint16_t quant16, uint16_t * verify_data)
|
||||
@ -94,14 +94,14 @@ uint16_t ZD24C02A_verify(uint32_t Addr, uint16_t quant16, uint16_t * verify_data
|
||||
uint16_t addr_vfy_data[8];
|
||||
uint16_t Err_read = 0;
|
||||
|
||||
if(quant16 > 8)
|
||||
if(quant16 > 4)
|
||||
{
|
||||
for(i = 0; i < (quant16-4); i += 8)
|
||||
for(i = 0; i < (quant16-4); i += 4)
|
||||
{
|
||||
copy16_to_8(verify_data, addr_vfy_data, 8);
|
||||
Err_read = ZD24C02A_verify_16(Addr+2*i, addr_vfy_data, 16);
|
||||
copy16_to_8(verify_data, addr_vfy_data, 4);
|
||||
Err_read = ZD24C02A_verify_16(Addr+2*i, addr_vfy_data, 8);
|
||||
if(Err_read) return Err_read;
|
||||
verify_data+=8;
|
||||
verify_data+=4;
|
||||
}
|
||||
}
|
||||
if(i < quant16)
|
||||
|
@ -16,14 +16,14 @@
|
||||
#define GPIO_PIN_SDAA 0U // GPIO number for I2C SDAA
|
||||
#define GPIO_PIN_SCLA 1U // GPIO number for I2C SCLA
|
||||
|
||||
#define TIME_OVER 1000
|
||||
#define TIME_OVER 100 //*0.1 mS, 1000 ~ 100 mS, 100 ~ 10mS
|
||||
|
||||
uint16_t TimerTimeouts = 0, ErrI2c = 0, ErrI2c1 = 0, ErrI2c2 = 0, ErrI2c3 = 0, ErrI2c4 = 0, Addr1[255];
|
||||
uint16_t RXdata, addrCount=0;
|
||||
volatile uint16_t TimerTimeouts = 0, ErrI2c = 0, ErrI2c1 = 0, ErrI2c2 = 0, ErrI2c3 = 0, ErrI2c4 = 0, ErrI2c5 = 0, Addr1[255];
|
||||
volatile uint16_t RXdata, addrCount=0;
|
||||
|
||||
void TimerBaseTimeoutInc(void)
|
||||
{
|
||||
TimerTimeouts++;
|
||||
if(TimerTimeouts < TIME_OVER*16) TimerTimeouts++;
|
||||
}
|
||||
|
||||
|
||||
@ -71,6 +71,10 @@ void I2CMasterInit(uint16_t I2C_OwnAddress, uint16_t I2CSlave_Address)
|
||||
//
|
||||
I2caRegs.I2CMDR.bit.BC = 0x0U;
|
||||
|
||||
|
||||
I2caRegs.I2CFFRX.bit.RXFFRST = 1;
|
||||
I2caRegs.I2CFFTX.bit.I2CFFEN = 1;
|
||||
I2caRegs.I2CFFTX.bit.TXFFRST = 1;
|
||||
//
|
||||
// Configure slave and own address
|
||||
//
|
||||
@ -129,6 +133,21 @@ uint16_t I2CWrite(uint16_t slaveAddr, uint16_t MemAdr, uint16_t byteCount, bool
|
||||
//
|
||||
uint16_t index = 0;
|
||||
|
||||
I2caRegs.I2CFFRX.bit.RXFFRST = 0;
|
||||
I2caRegs.I2CFFTX.bit.I2CFFEN = 0;
|
||||
I2caRegs.I2CFFTX.bit.TXFFRST = 0;
|
||||
I2caRegs.I2CFFRX.bit.RXFFRST = 1;
|
||||
I2caRegs.I2CFFTX.bit.I2CFFEN = 1;
|
||||
I2caRegs.I2CFFTX.bit.TXFFRST = 1;
|
||||
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CSTR.bit.BB == 1)&&(TimerTimeouts < TIME_OVER));
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
ErrI2c++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Configure slave address
|
||||
//
|
||||
@ -143,20 +162,12 @@ uint16_t I2CWrite(uint16_t slaveAddr, uint16_t MemAdr, uint16_t byteCount, bool
|
||||
//
|
||||
//Set Data Count
|
||||
//
|
||||
I2caRegs.I2CCNT = byteCount;
|
||||
|
||||
//
|
||||
// send Start condition
|
||||
//
|
||||
// I2caRegs.I2CMDR.bit.STP = 0x1;
|
||||
I2caRegs.I2CMDR.bit.STT = 0x1;
|
||||
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1;
|
||||
I2caRegs.I2CCNT = byteCount+1;
|
||||
|
||||
I2caRegs.I2CMDR.bit.NACKMOD = 0x0;
|
||||
|
||||
I2caRegs.I2CDXR.all = MemAdr ;
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CSTR.bit.BYTESENT != 0x1)&&(TimerTimeouts < TIME_OVER));
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
if(TimerTimeouts >= TIME_OVER) {ErrI2c++; return 1;}
|
||||
|
||||
//
|
||||
//transmit the bytes
|
||||
@ -164,27 +175,46 @@ uint16_t I2CWrite(uint16_t slaveAddr, uint16_t MemAdr, uint16_t byteCount, bool
|
||||
for(index=0; index < byteCount; index++)
|
||||
{
|
||||
I2caRegs.I2CDXR.all= I2C_TXdata[index];
|
||||
|
||||
}
|
||||
//
|
||||
// send Start condition
|
||||
//
|
||||
I2caRegs.I2CMDR.bit.STT = 0x1;
|
||||
//
|
||||
//wait till byte is sent
|
||||
//
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CSTR.bit.BYTESENT != 0x1)&&(TimerTimeouts < TIME_OVER));
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CFFTX.bit.TXFFST > 0)&&(TimerTimeouts < TIME_OVER*(byteCount+1)));
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
ErrI2c++;
|
||||
return 1;
|
||||
}
|
||||
I2caRegs.I2CFFTX.bit.TXFFINTCLR = 1;
|
||||
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
if(TimerTimeouts >= TIME_OVER) {ErrI2c1++; return 1;}
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CSTR.bit.NACK == 0x1)&&(TimerTimeouts < TIME_OVER));
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
ErrI2c1++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Send STOP condition if specified
|
||||
//
|
||||
if(sendStopCondition)
|
||||
{
|
||||
I2caRegs.I2CMDR.bit.STP = 0x1;
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CMDR.bit.STP != 0x0)&&(TimerTimeouts < TIME_OVER));
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
if(TimerTimeouts >= TIME_OVER) {ErrI2c2++; return 1;}
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
ErrI2c2++;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
TimerTimeouts = 0;
|
||||
while(TimerTimeouts < TIME_OVER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -207,39 +237,47 @@ uint16_t I2CRead(uint16_t slaveAddr, uint16_t byteCount, bool sendStopCondition,
|
||||
I2caRegs.I2CMDR.bit.MST = 0x1;
|
||||
I2caRegs.I2CMDR.bit.TRX = 0x0;
|
||||
|
||||
|
||||
uint16_t count = 0;
|
||||
|
||||
I2caRegs.I2CFFRX.bit.RXFFINTCLR = 0;
|
||||
I2caRegs.I2CCNT = byteCount;
|
||||
|
||||
I2caRegs.I2CMDR.bit.STT = 0x1;
|
||||
|
||||
//
|
||||
// Read the received data into RX buffer
|
||||
//
|
||||
TimerTimeouts = 0;
|
||||
while((count < (byteCount))&&(TimerTimeouts < TIME_OVER))
|
||||
while( (I2caRegs.I2CFFRX.bit.RXFFST < byteCount) && (TimerTimeouts < TIME_OVER*byteCount));
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
if(count == (byteCount-1)) {I2caRegs.I2CMDR.bit.NACKMOD = 0x1; }//I2caRegs.I2CMDR.bit.STP = 0x1;}
|
||||
if(I2caRegs.I2CSTR.bit.RRDY ==0x1)
|
||||
{
|
||||
RXdata = I2C_RXdata[count] = I2caRegs.I2CDRR.all;
|
||||
count++;
|
||||
}
|
||||
ErrI2c3++;
|
||||
return 1;
|
||||
}
|
||||
if(TimerTimeouts >= TIME_OVER) {ErrI2c3 += (byteCount - count); return 1;}
|
||||
|
||||
//
|
||||
// Send STOP condition
|
||||
//
|
||||
if(sendStopCondition)
|
||||
I2caRegs.I2CMDR.bit.STP = 0x1;
|
||||
|
||||
for(count=0; count < byteCount; count++)
|
||||
{
|
||||
I2caRegs.I2CMDR.bit.STP = 0x1;
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CMDR.bit.STP != 0x0)&&(TimerTimeouts < TIME_OVER));
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
if(TimerTimeouts >= TIME_OVER) {ErrI2c4++; return 1;}
|
||||
RXdata = I2C_RXdata[count] = I2caRegs.I2CDRR.all;
|
||||
}
|
||||
|
||||
// TimerTimeouts = 0;
|
||||
// while((I2caRegs.I2CSTR.bit.NACK == 0x1)&&(TimerTimeouts < TIME_OVER));
|
||||
// if(TimerTimeouts >= TIME_OVER)
|
||||
// {
|
||||
// ErrI2c4++;
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
I2caRegs.I2CMDR.bit.NACKMOD = 0x1;
|
||||
|
||||
TimerTimeouts = 0;
|
||||
while((I2caRegs.I2CMDR.bit.STP != 0x0)&&(TimerTimeouts < TIME_OVER));
|
||||
if(TimerTimeouts >= TIME_OVER)
|
||||
{
|
||||
ErrI2c5++;
|
||||
return 1;
|
||||
}
|
||||
I2caRegs.I2CSTR.bit.BYTESENT = 0x1;
|
||||
I2caRegs.I2CFFRX.bit.RXFFINTCLR = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -282,8 +282,8 @@ void getMessage_from_Cm_ZD24C02A(void)
|
||||
break;
|
||||
case WRITE:
|
||||
I2CErr = ZD24C02A_write(InAddr*2, InData, (uint16_t *)CMTOCPUXMSGRAM0_BASE);
|
||||
if(I2CErr) IPC_sendCommand(IPC_CPU1_L_CM_R, ZD24C02A_2K_I2C, FLASH_ERR, 0, 0);
|
||||
else IPC_sendCommand(IPC_CPU1_L_CM_R, ZD24C02A_2K_I2C, DONE_SUCCESS, 0, 0);
|
||||
if(I2CErr) IPC_sendCommand(IPC_CPU1_L_CM_R, FLASH_ERR, ZD24C02A_2K_I2C, 0, 0);
|
||||
else IPC_sendCommand(IPC_CPU1_L_CM_R, DONE_SUCCESS, ZD24C02A_2K_I2C, 0, 0);
|
||||
break;
|
||||
case VERIFY:
|
||||
MemOperationError = ZD24C02A_verify(InAddr*2, InData, (uint16_t *)CMTOCPUXMSGRAM0_BASE);
|
||||
|
Loading…
Reference in New Issue
Block a user