|
|
|
@ -53,7 +53,7 @@ uint8_t TWI_StartTransmission(TWI_t* const TWI,
|
|
|
|
|
}
|
|
|
|
|
else if ((status & (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm)) == (TWI_MASTER_WIF_bm | TWI_MASTER_RXACK_bm))
|
|
|
|
|
{
|
|
|
|
|
TWI_StopTransmission(twi);
|
|
|
|
|
TWI_StopTransmission(TWI);
|
|
|
|
|
return TWI_ERROR_SlaveResponseTimeout;
|
|
|
|
|
}
|
|
|
|
|
else if (status & (TWI_MASTER_WIF_bm | TWI_MASTER_RIF_bm))
|
|
|
|
@ -67,7 +67,7 @@ uint8_t TWI_StartTransmission(TWI_t* const TWI,
|
|
|
|
|
|
|
|
|
|
if (!(TimeoutRemaining)) {
|
|
|
|
|
if (TWI->MASTER.STATUS & TWI_MASTER_CLKHOLD_bm) {
|
|
|
|
|
TWI_StopTransmission(twi);
|
|
|
|
|
TWI_StopTransmission(TWI);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -114,24 +114,24 @@ uint8_t TWI_ReadPacket(TWI_t* const TWI,
|
|
|
|
|
{
|
|
|
|
|
uint8_t ErrorCode;
|
|
|
|
|
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(twi, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE,
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE,
|
|
|
|
|
TimeoutMS)) == TWI_ERROR_NoError)
|
|
|
|
|
{
|
|
|
|
|
while (InternalAddressLen--)
|
|
|
|
|
{
|
|
|
|
|
if (!(TWI_SendByte(twi, *(InternalAddress++))))
|
|
|
|
|
if (!(TWI_SendByte(TWI, *(InternalAddress++))))
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = TWI_ERROR_SlaveNAK;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(twi, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_READ,
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_READ,
|
|
|
|
|
TimeoutMS)) == TWI_ERROR_NoError)
|
|
|
|
|
{
|
|
|
|
|
while (Length--)
|
|
|
|
|
{
|
|
|
|
|
if (!(TWI_ReceiveByte(twi, Buffer++, (Length == 0))))
|
|
|
|
|
if (!(TWI_ReceiveByte(TWI, Buffer++, (Length == 0))))
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = TWI_ERROR_SlaveNAK;
|
|
|
|
|
break;
|
|
|
|
@ -139,13 +139,13 @@ uint8_t TWI_ReadPacket(TWI_t* const TWI,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TWI_StopTransmission(twi);
|
|
|
|
|
TWI_StopTransmission(TWI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t TWI_WritePacket(TWI_t* const twi,
|
|
|
|
|
uint8_t TWI_WritePacket(TWI_t* const TWI,
|
|
|
|
|
const uint8_t SlaveAddress,
|
|
|
|
|
const uint8_t TimeoutMS,
|
|
|
|
|
const uint8_t* InternalAddress,
|
|
|
|
@ -155,12 +155,12 @@ uint8_t TWI_WritePacket(TWI_t* const twi,
|
|
|
|
|
{
|
|
|
|
|
uint8_t ErrorCode;
|
|
|
|
|
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(twi, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE,
|
|
|
|
|
if ((ErrorCode = TWI_StartTransmission(TWI, (SlaveAddress & TWI_DEVICE_ADDRESS_MASK) | TWI_ADDRESS_WRITE,
|
|
|
|
|
TimeoutMS)) == TWI_ERROR_NoError)
|
|
|
|
|
{
|
|
|
|
|
while (InternalAddressLen--)
|
|
|
|
|
{
|
|
|
|
|
if (!(TWI_SendByte(twi, *(InternalAddress++))))
|
|
|
|
|
if (!(TWI_SendByte(TWI, *(InternalAddress++))))
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = TWI_ERROR_SlaveNAK;
|
|
|
|
|
break;
|
|
|
|
@ -169,14 +169,14 @@ uint8_t TWI_WritePacket(TWI_t* const twi,
|
|
|
|
|
|
|
|
|
|
while (Length--)
|
|
|
|
|
{
|
|
|
|
|
if (!(TWI_SendByte(twi, *(Buffer++))))
|
|
|
|
|
if (!(TWI_SendByte(TWI, *(Buffer++))))
|
|
|
|
|
{
|
|
|
|
|
ErrorCode = TWI_ERROR_SlaveNAK;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TWI_StopTransmission(twi);
|
|
|
|
|
TWI_StopTransmission(TWI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode;
|
|
|
|
|