National Semiconductor CP3BT26 User Manual page 191

Reprogrammable connectivity processor with bluetooth, usb, and can interfaces
Table of Contents

Advertisement

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

Advertisement

Table of Contents
loading

Table of Contents