English
Language : 

CP3BT26 Datasheet, PDF (191/278 Pages) National Semiconductor (TI) – Reprogrammable Connectivity Processor with Bluetooth-R, USB, and CAN Interfaces
acb->ACBctl1 |= ACBSTOP;
/* Send STOP bit
*/
/* Return success status....
*/
return (ACB_NOERR);
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; NAME: ACBStartX Initiates an ACB bus transaction by sending the Start bit, followed by the Slave address
;
and R/W flag. Checks for any ACB errors throughout this sequence and returns status.
;
; PARAMETERS: UBYTE Slave - I2C address of Slave device
;
UBYTE R_nW - Read/Write flag (0x01 or 0x00)
;
UWORD Count - Desired number of bytes (read/write)
;
; CALLS:
;
; RETURNED: error/success
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
UWORD ACBStartX (UBYTE Slave, UBYTE R_nW, UWORD Count)
{
ACB_T *acb;
UWORD Timeout;
/* Get address of ACB module
*/
acb = (ACB_T*)ACB_ADDRESS;
/* If Bus is Busy and we’re NOT the Master, return err */
if (acb->ACBcst & ACBBB && !(acb->ACBst & ACBMASTER))
return (ACBERR_NOTMASTER);
/* If we’re good to go, send Start condition
*/
acb->ACBctl1 |= ACBSTART;
/* Check if we’re the Bus Master with timeout
*/
Timeout = 100;
while (!(acb->ACBst & ACBSDAST) && Timeout--) /* Related to bus error problem
*/
{
if (acb->ACBst & ACBBER) {
/* If collision occurs, clear error and return status */
acb->ACBst |= ACBBER;
return (ACBERR_COLLISION);
}
}
if (!Timeout)
return (ACBERR_NOTMASTER);
acb->ACBsda = Slave | R_nW;
/* If timeout, we must NOT be the Master...signal error */
/* Now, send the address and R/W flag...
*/
/* Send address and R/W flag
*/
Timeout = 1000;
/* Failsafe for lockup
*/
/* Wait for address to be sent and ACK’d
*/
while (!(acb->ACBst & ACBSDAST) &&
!(acb->ACBst & ACBNEGACK)&&
--Timeout) {
if (acb->ACBst & ACBBER) {
acb->ACBst |= ACBBER;
/* If a bus error occurs while sending address, clear */
/* the error flag and return error status
*/
return (ACBERR_COLLISION);
}
}
KBD_OUT |= BIT0; // OScope marker
if (!Timeout)
return (ACBERR_TIMEOUT);
else if (acb->ACBst & ACBNEGACK)
return (ACBERR_NEGACK);
else {
/* If timeout, signal error
*/
/* Or if Slave does not reply, report busy/error
*/
/* Otherwise return success
*/
return (ACB_NOERR);
}
191
www.national.com