📄 basic.c
字号:
{
if(TxCompleteflag == SET) /* if the last byte has been transmitted */
{
TxCompleteflag = CLEAR; /* clear the ISR transmit complete flag */
Iic.ibcr.byte = (IBEN|TXRX); /* send stop signal (clear MSSL) */
TxBufferemptyflag = SET; /* set the non-ISR transmit buffer empty flag */
}
else /* last byte has not been transmitted */
{
if(Iic.ibsr.bit.rxak == CLEAR) /* if the slave acknowledged last transfer */
{
if(MasterRxFlag == SET) /* if the last transfer was an address and master is now to Rx */
{
Iic.ibcr.bit.txrx = CLEAR; /* switch to Rx mode */
dummyibdrRead = Iic.ibdr.byte; /* dummy read of IBDR register */
}
else /* last transfer was to instruct other slave to receive */
{
Iic.ibdr.byte = *TxPacketpositionptr; /* write next byte to IBDR */
if (TxPacketpositionptr == TxPacketendptr) /* if the last data has been Tx'd */
{
TxCompleteflag = SET; /* set the ISR transmit complete flag */
}
else /* there is still data to be transmitted */
{
TxPacketpositionptr++; /* move to next byte to Tx */
}
}
}
else /* slave did not acknowledge last transfer */
{
Iic.ibcr.byte = (IBEN|TXRX); /* send stop signal (clear MSSL) */
}
}
}
else /* module is to receive data */
{
if(RxPacketpositionptr == RxPacketendptr)/* if the last byte has been received */
{
Iic.ibcr.byte = (IBEN); /* send stop signal (clear MSSL) */
RxCompleteflag = SET; /* set the ISR receive complete flag */
}
else /* last byte has not been received yet */
{
if(RxPacketpositionptr == (RxPacketendptr - 1)) /* if the second last byte has been received */
{
Iic.ibcr.bit.txak = SET; /* disable active low acknowledge bit (signal to slave to stop Tx) */
}
else /* second last byte is still to be received */
{ /* do nothing here */
}
}
*RxPacketpositionptr = Iic.ibdr.byte; /* read the data from the slave */
if (RxCompleteflag == SET) /* if the last byte of data has been received */
{
RxCompleteflag = CLEAR; /* clear the ISR receive complete flag */
RxBufferfullflag = SET; /* set the receive buffer full flag */
}
else /* there is still data to receive */
{
RxPacketpositionptr++; /* increment the Rx packet position pointer */
}
}
}
else /* module is in slave mode */
{
if(Iic.ibsr.bit.ibal == SET) /* if module is now in slave mode because arbitration has been lost */
{
Iic.ibsr.bit.ibal = 1; /* reset the abritration flag */
if(Iic.ibsr.bit.iaas == SET) /* if this module has been addressed as slave */
{
if(Iic.ibsr.bit.srw == SET) /* if module is to transmit */
{
Iic.ibcr.bit.txrx = SET; /* switch to Tx mode */
Iic.ibdr.byte = *TxPacketpositionptr; /* write next byte to IBDR */
if(TxPacketpositionptr == TxPacketendptr) /* if the last byte has been transmitted */
{
TxBufferemptyflag = SET; /* raise transmit complete flag */
}
else /* last byte has not been transmitted */
{
TxPacketpositionptr++; /* move to next byte to Tx */
}
}
else /* module is to receive */
{
Iic.ibcr.bit.txrx = CLEAR; /* switch to Rx mode */
dummyibdrRead = Iic.ibdr.byte; /* dummy read of IBDR register */
}
}
else /* module has not been addressed as a slave */
{ /* do nothing here */
}
}
else /* arbitration was not lost */
{
if(Iic.ibsr.bit.iaas == SET) /* if this module has been addressed as slave */
{
if(Iic.ibsr.bit.srw == SET) /* if module is to transmit */
{
Iic.ibcr.bit.txrx = SET; /* switch to Tx mode */
Iic.ibdr.byte = *TxPacketpositionptr; /* write next byte to IBDR */
if(TxPacketpositionptr == TxPacketendptr) /* if the last byte has been transmitted */
{
TxBufferemptyflag = SET; /* raise transmit complete flag */
}
else /* last byte has not been transmitted */
{
TxPacketpositionptr++; /* move to next byte to Tx */
}
}
else /* module is to receive */
{
Iic.ibcr.bit.txrx = CLEAR; /* switch to Rx mode */
dummyibdrRead = Iic.ibdr.byte; /* dummy read of IBDR register */
}
}
else /* module has not been addressed as slave */
{
if(Iic.ibcr.bit.txrx == SET) /* if module is to transmit */
{
if(Iic.ibsr.bit.rxak == CLEAR) /* if the slave acknowledged last transfer */
{
Iic.ibdr.byte = *TxPacketpositionptr; /* write next byte to IBDR */
if(TxPacketpositionptr == TxPacketendptr) /* if the last byte has been transmitted */
{
TxBufferemptyflag = SET; /* raise transmit complete flag */
}
else /* last byte has not been transmitted */
{
TxPacketpositionptr++; /* move to next byte to Tx */
}
}
else /* module is not to transmit */
{
Iic.ibcr.bit.txrx = CLEAR; /* switch to Rx mode */
dummyibdrRead = Iic.ibdr.byte; /* dummy read of IBDR register */
}
}
else /* module is to receive data */
{
*RxPacketpositionptr = Iic.ibdr.byte; /* read IBDR register and store in current buffer location */
if(RxPacketpositionptr == RxPacketendptr) /* if the last packet has been received */
{
RxBufferfullflag = SET; /* set flag */
}
else /* last packet has yet to be received */
{
RxPacketpositionptr++; /* move to next byte to transmit */
}
}
}
}
}
}
/******************************************************************************
Function Name : _dummyISR
Engineer : M.Gallop
Date : 25/07/01
Parameters : NONE
Returns : NONE
Notes : Interrupt service routine for unused interrupt vectors.
******************************************************************************/
#pragma TRAP_PROC
void
_dummyISR( void )
{
for(;;); /* endless cycle */
}
/* End of interrupt service routines */
/* reset code segment to default */
#pragma CODE_SEG DEFAULT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -