Home
P90CL301 I
Contents
1. APPLICATION NOTE P90CL301 I C driver routines AN94078 Phils Semiconductors PHILIPS Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 Abstract The P90CL301 is a highly integrated 16 32 bit micro controller especially suitable for applications requiring low voltage and low power consumption It is fully software compatible with the 68000 Furthermore it provides both standard as well as advanced peripheral functions on chip One of these peripheral functions is the PC bus This report describes worked out driver software written in C to program the P90CL301 FC interface It also contains interface software routines offering the user a quick start in writing a complete PC system application Purchase of Philips IC components conveys a license under the I C patent to use the compo nents in the IC system provided the system conforms to the I C specifications defined by Philips Philips Electronics N V 1997 All rights are reserved Reproduction in whole or in part is prohibited without the prior written consent of the copy right owner The information presented in this document does not form part of any quotation or contract is believed to be accurate and reliable and may be changed without notice No liability will be accepted by the publisher for any consequence of its use Publication thereof does not convey nor imply any license under patent or other ind
2. 21 Application Note AN94078 DEE k kok ok kok k kok ok kok RON ROO ROO kok ok oko kok ok kok ke kok kok k kok ke kok k kok k kok k kok k kok k kok k kok kok k kok Ef x R break break break break break break break Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 void I2C_Write I2C_MESSAGE msg KR I ok kok k kok k kok k k UK k Input s msg I C message Returns None Description Write a message to a slave device PROTOCOL lt S gt lt SlvA gt lt W gt lt A gt lt D1 gt lt A gt lt Dnum gt lt N gt lt P gt KKK KK KK KK kk I 2 2 kk kk KK KK KK k kk k kk kk kk 2 2 k k k k K k k 2 kk 2 2 2 KK k 2 2 2 2 2 2 22 2 2 2 KK KK iicTfr nrMessages 1 iicTfr p message p iicMsg p iicMsg 0 msg StartTransfer void I2C WriteRepWrite I2C MESSAGE msgl I2C MESSAGE msg2 S EKEK KK ok kok k kok k kok k kok k kok ko kok k kok U e Input s msgl first I C message msg2 second I C message Returns None Description Writes two messages to different slave devices separated x by a repeated start condition PROTOCOL lt S gt lt Slvl1A gt lt W gt lt A gt lt D1 gt lt A gt lt Dnuml gt lt A gt lt S gt lt Slv2A gt lt W gt lt A gt lt D1 gt lt A gt lt Dnum2 gt lt A gt lt P gt DEE EEE ok kok ok kok k kok oko k RR ok kok ok kok ok kok o ROO kok k kok ke kok k kok k kok k kok k kok k kok k kok kok
3. Read the time from the real time clock chip PCF8583 Displays the time on LCD module PCF8577 and LED module SAA1064 Reads keys from I O expander PCF8574 x pE Depending of pushed keys send tone to loudspeaker PCD3312 LE xy BRR KK KK KK 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 22 22 2 2 2 22 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 222 f d History LE x 92 12 10 P H Seerden Initial version VE x ok ok kok ok kok RK k kok k kok k kok k kok k kok k kok k kok kok k kok RER include lt stdio h gt include i2cexprt h define PCF8574 WR 0x7E i2c address I O poort write define PCF8574 RD 0x7F i2c address I O poort read define PCD3312_WR Ox4A i2c address DTMF define SAA1064_WR 0x76 i2c address 7 segm Led define SAA1064_RD 0x77 i2c address 7 segm Led define PCF8577 WR 0x74 i2c address 7 segm LCD x define PCF8583 WR OxA2 i2c address Clock define PCF8583 RD OxA3 i2c address Clock define LCDA 0x80 LCD segment a define LCDB 0x40 LCD segment b define LCDC 0x20 LCD segment c define LCDD 0x10 LCD segment d define LCDE 0x08 LCD segment e 7 define LCDF 0x04 LCD segment f define LCDG 0x02 LCD segment g define LCDDP 0x01 LCD segment dp define LEDA 0x04 LED segment a define LEDB 0x08 LED segment b EJ define LEDC 0x40 LED segment c define LEDD 0x20 LED segment d define LEDE 0x
4. arista ete ehe tenente iue tegunt eee eaters 7 2 Function l deseription i xu Wess aes Shag dened Sk a od al kde Anal etd nln REDE ie edd ADU ee a ES 8 A fait abutere iie qi 8 2 2 Inp t definition io ee oL UR c Un eu GR dabei uml ea a ede 9 2 3 Output definition sce ts er ar ID reque X nu eg Ded Mec Ree ue gun 9 2 4 Performance AA er ne E ee ue bh bald le eG ora eR EST Ded a ceca 9 2 5 USING INTEMUPIS 2 0 der Sener neces de is pad da 10 2 6 Using an operating system 0 cece nen nennen ernennen 10 2 x Error handling nemo ee Re DENE Le EE CE 10 3 External application interface 0 cee nennen 11 3 1 External data interface ned ain aaa ia ins E ME ENS 11 3 2 External function interfaces eaae a a e R A A EN E A UA hn 12 3 3 Interface layer example eari serr ke nRa ERATE EIE RARE m RATARA a 15 4 Internal Wotklng ser il rer EE iG tea EEE po E ein ge 16 Hx Slavo operation x reei ea a REE Mes nae prd ee BA le ka ER n ben E ice ee AEEA 18 6 Modellirig hlerarehy ra posta z engen AEE AA 19 Appendices sans A ERRE ade BV adn AREKE aan bee eda eee 20 APPENDIX gt T2GINTEGQ GC p t rau 1 Vinee re btu ae ot an ieee ra da eda Diana 20 APPENDIX IN I2CMASTRB G sonia ee u re oio a ced un 24 APPENBDIXTI I26ESEAVEC cre dre A Ee A DOE d E UT E are ais 27 APPENDDGIW IPODRIVBO ra ea IAE DER EE rn 30 APPENDIX J2GEXPRTH a dce p t d sata rasen eure REF UE RE 32 APPENDIXYII IZGDRIVR H nio ia hea up
5. time outs software loops retries and error messages The user must adapt these functions to his own system needs I2CEXPRT H This module include file contains definitions of all global constants function prototypes data types and structures needed by the user application Include this file in the user application source files EXAMPLE C This program uses the driver package to implement a simple application on the Microcore 5 and an I2C demonstration board There are different approaches to link your driver and application software One of them is that you separately link the object obj files your application needs A second possibility is to use the driver package library called 12C90301 LIB which is also at the distribution disk This approach has the advantage that depending on the function calls in your code the linker loads object modules from the library Philips Semiconductors P90CL301 IC driver routines Application Note Appendices APPENDIX I2CINTFC C ok k kok ok kok ok kok k oko k kok k kok k kok k kok k kok k kok k kok RR Acronym I C Inter IC bus for P90CL301 Name of module I2CINTFC C Scope general I C driver 12nc I XXXX XXX XXXX X Creation date 1994 08 19 x Program language C Name P H Seerden 8 J C Copyright 1994 Philips Semiconductors B V E Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven
6. void I2C WriteRepWrite I2C MESSAGE msg1 I2C MESSAGE msg2 void I2C WriteRepRead I2C MESSAGE msg1 l2C MESSAGE msg2 void I2C Read Il2C MESSAGE msg void I2C ReadRepRead I2C MESSAGE msg1 I2C MESSAGE msg2 voidl2C ReadRepWrite I2C MESSAGE msg1 l2C MESSAGE msg2 Furthermore the module I2CINTFC C contains the functions StartTransfer in which the actual call to the driver program is done and the function 2cReady which is called by the driver after the completion of a transfer The flag drvStatus is used to test check the state of a transfer In the StartTransfer function a software time out loop is programmed Inside this time out loop the MainStateHandler is called if the driver is in polling mode and the SCON SI flag is set If a transfer has failed error or time out the StartTransfer function prints an error message via UART to Microcore 5 HMON terminal and it does a retry of the transfer However if the maximum number of retries is reached an exception interrupt Trap 15 is generated through which the micro jumps into the HMON debug monitor code on the Microcore 5 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 4 Internal working The P90CL301 on chip logic provides a serial interface that meets the I C bus specification and supports all transfer modes from and to the bus In order to enable the interface the port pins P10 and P11 should be programmed to their alternate function by
7. 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 222 2 2 2 2 2 22 2 2 2 2 2 2 IE 2 2222 2 2 2073 LE Description a Hardware register I O port description file of the P90CL301 16 bit micro controller for use in C programs VA ey Registers which don t contain individual bits are defined with x BYTE AT and or WORD AT the use of those registers is as follows registers name value i e TH 0x45 8 Registers which do contain individual bits are defined as unions x This enables you to choose between byte and bit access the usage is as follows x register name reg value i e TCON reg 0x45 or register name bit bit name value i e SCON bit ti 0 LE E LE n BRK RK ok ok KKK ok k k k k k ok ok k k k k k k 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 22222 2 2 2073 EI History JR 92 11 09 P H Seerden Initial version 92 12 07 J Pijnenburg Add bit definitions 92 08 16 P H Seerden Modified for 90CL301 RE KR kok ok kok k kok k k kok k kok k kok k kok k kok k kok k kok k kok RR define BYTE AT x unsigned char x define WORD AT x unsigned short int x define LONG AT x unsigned long int x en me m I ICTU SML a O NOTET OE Ngee nen ne S e m KD men Mac o rn Leu Register Bit Definitions SYSCON mp mr cn ce c SS E RR ee a ts Bl a SS ee ae typedef union
8. Bu Bu Bu Bu sndBu sndBu sndBu sndBu sndBu sndBu FH Fh Fh Fh Fh Fh Eh FH FH FH FH FH FH FH FH 8 I2C Write amp sndMsqg OxFF Soo 0000000000000 0x01 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 Ox3A 0x29 Ox3B 0x3C 0x3D 4 start of vector table on mcore 5 56 2 amp OxOF brea brea brea brea brea brea brea brea brea brea brea brea brea brea brea brea 40 Interrupt level 2 led brightness sub address seconds minutes hours set clock sub address Application Note Ey 87 El x Ei AN94078 Philips Semiconductors P90CL301 I C driver routines void main void BYTE oldseconds 0 Init while 1 HandleKeys rtcBuf 0 2 I2C WriteRepRead amp rtcMsgl amp rtcMsg2 if rtcBuf 0 oldseconds oldseconds rtcBuf 0 lcdBuf 0 0 if oldseconds amp 1 ledBuf 1 lcdTbl rtcBuf 2 gt gt 4 else lcdBuf 1 lcdTbl rtcBuf 2 gt gt 4 lcdBuf 2 ledTbl rtcBuf 2 amp 0x0F lcdBuf 3 lcdTbl rtcBuf 1 gt gt 4 ledBuf 4 lcdTbl rtcBuf 1 amp 0x0F 2C_Write amp lcdMsg ledBuf 0 1 ledBuf 1 2 ledBuf 2 ledTbl rtcBuf 0 gt gt 4 ledBuf 3 ledTbl rtcBuf 0 amp 0x0F ledBuf 4 2 2C_Write amp ledMsg 41 sub address LCDDP Applic
9. The Netherlands x as x All rights are reserved Reproduction in whole or in part is KY prohibited without the written consent of the copyright owner E JR BRK KR ok ok k k k k 2 2 k k k k k 2 2 2 2 2 2 2 2 2 2 222 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 kok kok 2 2 2 2222 f as Description xy External interface to the driver for the I C interface on the Philips P90CL301 microcontroller Ji kj This module contains the EXAMPLE interface functions used by Le the application to do I C master mode transfers d LE V ie ic History LE 94 02 22 P H Seerden Initial version FF es ok ok kok ok kok ok ok k kok k kok k kok k kok k kok k kok k kok k kok k kok RER include i2cexprt h include i2cdrivr h include reg90301 h static BYTE drvStatus Status returned by driver static I2C_MESSAGE p iicMsg 2 pointer to an array of 2 I2C mess static I2C TRANSFER iicTfr static void I2cReady BYTE status BYTE msgsDone BRK KR ok ok KKK 2 22 22 2 2 2 2 22 2 2 2 ok oko 2 2 2 2 2 22 2 2 2 202 2 2 I Input s status Status of the driver at completion time msgsDone Number of messages completed by the driver Output s None Returns None Description Signal the completion of an I C transfer This function is E passed as parameter to the driver and called by the drivers interrupt handler eI KKK KK KK KA 2 222 2 22 KK KK k
10. a a reg 34 APPENDIX VII REG90301 H ads ar heer Le A a 35 APPENDIX VIII EXAMPLE C 2 2 sm a hs 38 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 1 Introduction This report describes an I C driver for the P90CL301 16 32 bit 68000 based micro controller This driver is the interface between application software and the I C device s These devices conform to the serial bus interface protocol specification as described in the I C reference manual The I C bus consists of two wires carrying information between the devices connected to the bus Each device has its own 7 bit address It can act as a master or as a slave during a data transfer A master is the device that initiates the data transfer and generates the clock signals needed for the transfer At that time any addressed device is considered a slave The IC bus is a multi master bus This means that more than one device capable of controlling the bus can be connected to it This driver supports both master and slave message transfers as well as polled and interrupt driven message handling The driver will be linked to the application It is completely written in C programming language Both the software structure and the interface to the application are described separately The driver program has been tested as thoroughly as time permitted however Philips cann
11. driver are gt The number of messages to exchange transfer gt The slave address of the I C device for each message gt The data direction read write for all messages gt The number of bytes in each message gt In case of a write messages the data bytes to be written 2 3 Output definition Outputs application s view from the driver are gt Status information success or error code gt The number of messages actually transferred not equal to the requested number of messages in case of an error gt For each read message The data bytes read 2 4 Performance The clock speed of the I2C bus depends of the oscillator frequency of your controller To set the right speed in the P90CL301 two registers have to be written SYSCON and SCON Therefore no constant definitions are given in the file I2CDRIVR H The clock speed is programmable ranging up to 100 KHz To select the correct initialization divisor values refer to the User s Manual or the data sheet of the P90CL301 After that change the SCON values in the file I2CDRIVR H with the correct CR2 CR1 and CRO bits default 000 and re compile the module I2CDRIVR C Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 2 5 Using interrupts Normally default the driver operates in polling mode If a transfer is applied for the driver interface function will not return until the transfer has ended To let the driver operat
12. k kk kk kk kk 2 2 2 KK 2 RARA CK Ck 2 2 2 2 2 2 2 2 2 k 2 2 2 2 2 2 2 2 drvStatus status 20 AN94078 Philips Semiconductors P90CL301 IC driver routines static void StartTransfer void RR KKK KKK KKK KA RRA RARA Input s None Output s statusfield of I2C_TRANSFER contains the driver status I2C OK Transfer was successful I2C TIME OUT Timeout occurred Otherwise Some error occurred Returns None Description Start I C transfer and wait with timeout until the k driver has completed the transfer s LONG timeOut BYTE retries 0 do drvStatus I2C_BUSY I2C_Transfer amp iicTfr I2cReady timeOut 0 while drvStatus I2C_BUSY if timeOut gt 60000 drvStatus I2C TIME OUT if PICR3 0x70 0 level 0 gt polling if SCON amp 0x08 wait until SI bit is set MainStateHandler if retries 6 printf retry counter expired n fatal error So asm trap 15 escape to debug monitor else retries switch drvStatus case I2C_OK break case I2C_NO_DATA printf buffer empty n case I2C_NACK_ON_DATA printf no ack on data n case I2C_NACK_ON_ADDRESS printf no ack on address n case I2C_DEVICE_NOT_PRESENT printf device not present n case I2C_ARBITRATION_LOST printf arbitration lost n case I2C_TIME_OUT printf time out n default printf unknown status n while drvStatus I2C_OK
13. register define CS1N WORD AT OxFFFF8A02 chip select 1 control register x define CS2N WORD AT OxFFFF8A04 chip select 2 control register Rel define CS3N WORD AT OxFFFF8A06 chip select 3 control register x7 define CS4N WORD AT OxFFFF8A08 chip select 4 control register K define CS5N WORD_AT 0xFFFF8A0A chip select 5 control register define CS6N WORD AT OxFFFF8A0C chip select 6 control register define CSBTN WORD_AT OxFFFF8A0E chip select boot control register 37 AN94078 Philips Semiconductors P90CL301 IC driver routines Application Note APPENDIX VIII EXAMPLE C ok RK RK k kok k oko k kok k kok k kok k kok k kok k kok k kok k kok RR Acronym I2C Inter IC bus EJ Name of module EXAMPLE C ui Scope Application software 12nc i MEX XXX XXXX X Creation date 1994 10 08 Program language C Name P H Seerden es LE Jp 7 C Copyright 1994 Philips Semiconductors B V yE Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 JD x All rights are reserved Reproduction in whole or in part is x prohibited without the written consent of the copyright owner LE EJ VE 2 2 2 22 2 2 2 22 22 2 2 2 22 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 22 2 d Description LE I C driver test for P90CL301 x JP Runs on MICROCORE 5 and I C evaluation board type OM1016 yo x
14. with own slave Data byte received in SDAT ACK returned 88H Addressed with own slave Data byte received in SDAT NOTACK returned 90H Addressed with general call Data byte received in SDAT ACK returned 98H Addressed with general call Data byte received in SDAT NOTACK returned AOH A STOP or repeated START condition has been received Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 Slave transmitter AOH A STOP or repeated START condition has been received A8H Own SLV_R has been received ACK returned BOH Arbitration lost in SLV R W as master own SLV R received ACK returned B8H Data byte has been transmitted ACK received COH Data byte has been transmitted NOTACK received Miscellaneous 00H Bus error during master or selected slave mode due to an erroneous START or STOP condition The procedure MainStateHanaler in I2CDRIVR C checks the status in SSTA and calls either the function HandleMasterState in I2CMASTR C or the function HandleSlaveState in I2CSLAVE C Calling of these functions is done via two initialized pointers Both functions contain a switch case statement on SSTA to handle the right I C status If a master transfer is completed a function readyProc in the application or interface is called If a slave transfer is completed the slave status SLAVE_READY is set see also section 3 2 Philips Semiconductors P90CL301 IC driver routines Application Not
15. writing to the port control register PCON The CPU interfaces to the lC logic via four hardware registers SCON control register SSTA status register SDAT data register and SADR slave address registers After completing the transmission or reception of each byte address or data the SI flag in the SCON register is set In interrupt driven mode an interrupt is sent to the micro and the interrupt service handler will be called In polling mode this is done by software At that time register SSTA holds one of the following status codes Master transmitter 08H A start condition has been transmitted 10H A repeated start condition has been transmitted 18H SLV W has been transmitted ACK received 20H SLV W has been transmitted NOTACK received 28H DATA from SDAT has been transmitted ACK received 30H DATA from SDAT has been transmitted NOTACK received 38H Arbitration lost in SLV_ R W or DATA Master receiver 38H Arbitration lost while returning NOTACK 40H SLV R has been transmitted ACK received 48H SLV R has been transmitted NOTACK received 50H DATA in SDAT received ACK returned 58H DATA in SDAT received NOTACK returned Slave receiver 60H Own SLV W has been received ACK returned 68H Arbitration lost in SLV_R W as master own SLV W received ACK returned 70H General call has been received ACK returned 78H Arbitration lost in SLV_R W as master general call received ACK returned 80H Addressed
16. 10 LED segment e EJ define LEDF 0x01 LED segment f ua define LEDG 0x02 LED segment g define LEDDP 0x80 LED segment dp df 38 AN94078 Philips Semiconductors P90CL301 const BYTE lcdTbl const BYTE ledTbl 000000 000000 tatic tatic tatic tatic tatic iopBuf IESSAGE _MESSAGE IESSAGE IESSAGE IESSAGE IESSAGE ALC LC LC LC LC LC LC LC LC LC LE 0 LC LC LC LC LE y III II IB II eet ECO bo o AE ELE GB p gx y DA DB DA DA DB DA DA DA DA DA DA LC LC LC LC LC LC LC LC LC LC LC LC ERE EEE EEE EE 1x 3 EJ El E E DH E E E E B a B B UUUUUUUUUUU 350 DC B a B B REC Es F B B UUUUUUUUUUU B DC Li LC LC LC LC LC LC LC LC LC LC LC Gl El PLE E OG BII IC driver routines DC DG DG DF DG DG DC DC DC DC DD DC DG DG DF DG DG DC DC DC DC DD LC LC LC LC LC LC LC LC LC LC LE LE LE LE LE LE LE LE LE LE DD DD DD DC DC DC DD DD DE DE DD DD DD DC DC DC DD DD DE DE LCDE LCDF LCDE LCDC LCDD LCDD LCDE LCDE LCDF LCDG LCDF LCDG LCDF LCDG LCDG LEDE LEDF LEDE LEDC LEDD LEDD LEDE LEDE LEDF LEDG LE
17. 2 2 2 2 2 2 2 2 2 2 kkk kkk kk f A History RE x 94 08 08 P H Seerden Initial version F xy A ok k kok ok kok ok kok k oko k kok k kok k kok A include i2cexprt h include i2cdrivr h include reg90301 h void masterProc void slaveProc NoInitErrorProc NoInitErrorProc static void NoInitErrorProc void RK KKK KKK 2 2 ok ok k kok je k k k k k k k k Input s none Output s none Returns none Description ERROR Master or slave handler called while not initialized AAA SCON RELEASE BUS NOACK clr STO AA and SI E 30 AN94078 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 void MainStateHandler void ok k kok ok kok k kok k kok RK Input s none Output s none Returns none Description Main event handler for I2C KKK KK kk k KK 2 2 2 2 22 kk kk k KK k kk k kk k kk k 2 KK KK k k k k 2 2 2 2 k k kk 2 ke ko 2 2 2 2 2 2 2 2 2 2 2 2 I KK KK if SSTA lt 0x60 masterProc else slaveProc interrupt void I2C_Interrupt void BORK RK KK KR 2 22 22 2 2 k k k 2 2 2 k k k k k k Input s none Output s none Returns none Description Interrupt handler for I2C m The address of this function must be loaded into one of the on chip autovectors OK CKCKCK AR 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 22 2
18. 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2222 2 2 2073 LE History LE x 94 08 08 P H Seerden Initial version El F x m KKK ok kok RK k kok k kok k kok k kok k kok k kok k kok k kok k kok RR include i2cexprt h include i2cdrivr h include reg90301 h extern void masterProc static I2C_TRANSFER tfr Ptr to active transfer block static I2C MESSAGE msg ptr to active message block static void readyProc BYTE BYTE proc to call if transfer ended Static BYTE msgCount Number of messages to sent E Static BYTE dataCount bytes send received of current message 24 AN94078 Philips Semiconductors P90CL301 I C driver routines static void HandleMasterState void ok k kok k kok k kok k kok k kok RR k k k Input s none Output s none Returns none Description Master mode state handler for I2C bus LEE EEE ok kok ok kok k kok ok ok ok kok ke kok ok oko kok ROO ROO ROO ROO ROO kok k kok k kok k kok k 2 k kok k kok 2 RA switch SSTA gt gt 3 00 08 10 18 28 20 48 30 38 40 50 58 gt gt 3 for faster code case 0 Bus Error has occurred SCON GENERATE_STOP release bus clr STA and SI break case 1 repeated Start condition has been transmitted case 2 Slave address R W are transmitted SDAT msg gt address SCON RELEA
19. 2 2 2 2 22 22 2 2 22222 MainStateHandler calls procedure to handle the current state void I2C_InstallInterrupt BYTE intLevel S EEE KK ok kok k kok k kok k kok k kok U RR Input s intLevel Interrupt level number from 0 7 Output s none Returns none Description Install interrupt for I C CK KK oko ok 222 22 2 2 2 22 22 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 22 2 2 2 2 22 2 2 2 22 222 2 2 22 22 2 2 2 kk kkk PICR3 PICR3 intLevel lt lt 4 0x80 31 Philips Semiconductors P90CL301 I C driver routines APPENDIX V I2CEXPRT H Application Note KR KI ok kok k kok k ok k kok k kok k kok k kok k kok k kok k kok k kok k kok k kok kk kk kk k kk IRR IR AR I AK f Acronym I2C Inter IC bus f Name of module I2CEXPRT H Scope Application software 12nc XXXX XXX XXXX X Creation date 1992 12 10 Program language C EY Name P H Seerden i as KY C Copyright 1993 Philips Semiconductors B V el Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 x All rights are reserved Reproduction in whole or in part is prohibited without the written consent of the copyright owner JE 07 BRK RK ok ok KK KI 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 kok ok KC 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 IE kkk kk kkk f Ji ay Description Jet This m
20. 2 2 kok k KARA iicTfr nrMessages 2 iicTfr p message p iicMsg p iicMsg 0 msgl p iicMsg 1 msg2 StartTransfer 23 Philips Semiconductors P90CL301 IC driver routines Application Note APPENDIX II I2CMASTR C ok RR ok kok k kok k kok k kok k kok k kok k kok k kok k kok k kok k kok RR Acronym I C Inter IC bus for P90CL301 ay Name of module I2CMASTR C xy Scope Universal I C driver 12nc 1 XXXX XXX XXXX X Creation date 1994 08 08 Program language C Name P H Seerden JE Jp 7 C Copyright 1994 Philips Semiconductors B V yE Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 JD x All rights are reserved Reproduction in whole or in part is prohibited without the written consent of the copyright owner LE EJ EEE 3 2 2 22 22 2 2 ok oko oko ok 2 2 2 2 2 2 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 kkk kk ui Description LE i JE Driver for the I C hardware interface on the Philips P90CL301 x microcontroller A Part of the driver that handles master bus transfers ee Everything between a Start and Stop condition is called a TRANSFER One transfer consists of one or more MESSAGES y To start a transfer call function I2C_Transfer Xf Le BRR RR ok ok KKK 2 22 22 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22
21. AGE msg2 extern void I2C ReadRepWrite I2C MESSAGE msgl I2C MESSAGE msg2 33 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 APPENDIX VII I2CDRIVR H ok RK I ok kok ok kok k oko k kok k kok k kok k kok k kok k kok k kok k kok k kok kok k kok RR RRA ARK RRA RA KA I AK Acronym I C Inter IC bus for P90CL301 Name of module I2CDRIVR H xf Scope I C driver x 12nc i XXXX XXX XXXX X Creation date 1994 22 02 Program language C E Name P H Seerden Z LE XJ C Copyright 1994 Philips Semiconductors B V ig Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 LE x All rights are reserved Reproduction in whole or in part is prohibited without the written consent of the copyright owner JE x BRK RK KK KKK 2 22 22 ok ok 2 2 2222 2 2 2 22 2 2 oko k KC 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 IE 2 2222 2 2 2073 Description LE This module consists of local within I C subsystem declarations of the I C iicdrv c driver KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK AH AH AH AH A A A A AH KK K ay History JL x 16 08 94 P H Seerden Initial version E xf JH x KKK ok kok RK k oko k kok k kok k kok k kok k kok k kok k kok k kok RR define SLAVE IDLE 0 defi
22. DF LEDG LEDF LEDG LEDG 39 DER LAN AWNH O blank POO TOM ww O blank Application Note AN94078 Philips Semiconductors P90CL301 IC driver routines static void Init void static void HandleKeys void void otr define VECTOR BASE ptr ptr void void VECTOR BASE I2C Interrupt 0x80000 I2C InitializeMaster I2C InstallInterrupt 2 ledMsg ledMsg ledMsg ledBuf ledBuf address nrBytes buf O 0 1 0x4 7 SAA1064 WR 2 I2C Write amp ledMsg ledMsg rtcBuf rtcBuf rtcBuf rtcBuf rtcMsg rtcMsg rtcMsg rtcBuf rtcMsg rtcMsg nrBytes 2 0x0 0x5 3 0x2 address nrBytes DUB 0 1 2 0 2 nrBytes buf rtcMsg2 address rtcMsg2 nrBytes rtcMsg2 buf iopMsg iopMsg iopMsg sndMsg sndMsg sndMsg lcdMsg lcdMsg lcdMsg address buf nrBytes address buf nrBytes address buf nrBytes 0 9 3 5 ledBuf PCF8583 WR E rtcBuf I2C Write amp rtcMsgl 1 rtcBuf PCF8583_RD 3 rtcBuf PCF8574_RD iopBuf r PCD3312_WR sndBuf 1 PCF8577_WR lcdBuf 5 I2C_Read amp iopMsg switch case case case case case case case case case case case case case case case case iopBuf snd snd snd snd snd snd snd snd snd snd APH O aI GOT DUN o PFK ha Os W 0 Bu Bu Bu Bu Bu Bu
23. FF8318 Timer 1 channel 1 register Eh define T1C2 WORD AT OxFFFF831A Timer 1 channel 2 register ard define T1SR BYTE_AT OxFFFF831D Timer 1 status register KR define TIPR BYTE_AT OxFFFF831F Timer 1 prescaler reload reg Ac T P WATCHDOG T ATE SER BEER SS SS O re SS n EATUR E es SS m ee REN define WDTIM BYTE AT OxFFFF8401 Watchdog Timer Register Ax define WDCON BYTE AT OxFFFF8403 Watchdog Control Register YA 36 Philips Semiconductors P90CL301 IC driver routines Application Note ny m Let s PE PORT REGISTERS x EIE a M ER n AA define PCON BYTE AT OxFFFF8503 P port control register define PRL BYTE AT OxFFFF8505 P port port latch LSB 7 define PPL BYTE AT OxFFFF8507 P port port pin LSB define PRH BYTE AT OxFFFF8509 P port port latch MSB define PPH BYTE_AT OxFFFF850B P port port pin MSB define SPCON BYTE AT OxFFFF8109 SP port control register zy define SPR BYTE AT OxFFFF810B SP port latch define SPP BYTE AT OxFFFF810D SP port pin A E A A G JA UART E A T ee define SBUFO BYTE AT OxFFFF8601 UARTO transmit receive reg define SCONO SCONX TYPE OxFFFF8603 UARTO control register El define SBUF1 BYTE_AT 0xFFFF8605 UART1 transmit receive reg define SCON1 SCONX TYPE OxFFFF8607 UART1 contro
24. K ok kok ok kok k kok k kok k kok k kok k kok k kok k kok k kok k kok RR EXPORTED DATA DECLARATIONS s ok k kok ok kok ok kok k kok k kok k kok k kok k kok k kok k kok k kok k kok RR Status Errors define I2C OK 0 transfer ended No Errors define I2C BUSY T transfer busy define I2C ERR 2 err general error define I2C NO DATA 3 err No data in block define I2C NACK ON DATA 4 err No ack on data x define I2C NACK ON ADDRESS 5 err No ack on address El define 12C_DEVICE_NOT_PRESENT 6 err Device not present 87 define I2C_ARBITRATION_LOST 7 err Arbitration lost define 12C_TIME_OUT 8 err Time out occurred define I2C_SLAVE_ERROR 9 err slave mode error define I2C INIT ERROR 10 err Initialization not done KR kok ok kok ok kok k oko k kok k kok k kok k kok k kok k kok k kok k kok RR INTERFACE FUNCTION EZCR Q UICQ TY POEUS el ok k kok ok kok ok kok k kok k kok k kok k kok k kok A extern void I2C InitializeMaster void extern void I2C InitializeSlave BYTE slv BYTE buf BYTE size extern void I2C InstallInterrupt BYTE intLevel extern interrupt void I2C Interrupt void extern void I2C Write I2C MESSAGE msg extern void I2C WriteRepWrite I2C MESSAGE msgl I2C MESSAGE msg2 extern void I2C WriteRepRead I2C MESSAGE msgl I2C MESSAGE msg2 extern void I2C Read I2C MESSAGE msg extern void I2C ReadRepRead I2C MESSAGE msgl I2C MESS
25. KK iicTfr nrMessages 2 iicTfr p message p iicMsg p iicMsg 0 msgl p iicMsg 1 msg2 StartTransfer void I2C_WriteRepRead I2C_MESSAGE msgl I2C_MESSAGE msg2 ok ok kok ok kok ok kok k kok k kok k kok k kok k kok k RR k k Input s msgl first I C message msg2 second I C message Returns None Description A message is sent and received to from two different slave devices separated by a repeat start condition PROTOCOL lt S gt lt Slv1A gt lt W gt lt A gt lt D1 gt lt A gt lt Dnuml gt lt A gt lt S gt lt Slv2A gt lt R gt lt A gt lt D1 gt lt A gt lt Dnum2 gt lt N gt lt P gt Sk kok k kok ok kok ok kok ok kok ROO ROO ROO kok ok kok ok 2 2 kok o kok kok k kok ke kok k 2 k kok k kok k kok k kok k kok kok KK KK iicTfr nrMessages 2 iicTfr p message p iicMsg p iicMsg 0 msgl p iicMsg 1 msg2 StartTransfer void I2C_Read I2C_MESSAGE msg ok k kok ok kok k ok k kok k kok U KK Input s msg I C message Returns None Description Read a message from a slave device PROTOCOL lt S gt lt SlVA gt lt R gt lt A gt lt D1 gt lt A gt lt Dnum gt lt N gt lt P gt KKK KK KK KK kk I I KK KK KK k kk k kk 2 2 22 2 KK KK AK 2 2 2 2 2 k k k k 2 2 2 k k k k k k k 2 2 2 2 2 2 iicTfr nrMessages 1 iicTfr p message p iicMsg p iicMsg 0 msg StartTransfer 22 Philips Semiconductors P90CL301 IC driver rout
26. OACK return NACK on first byte break 80 case 16 90 case 18 Data received ACK returned slaveBuf count SDAT read data if count size SCON RELEASE_BUS_NOACK return NACK on next byte else SCON RELEASE_BUS_ACK return ACK on next byte break 88 case 17 98 case 19 data byte received NACK returned Xy slaveStatus SLAVE_RCV_ERROR SCON RELEASE_BUS_ACK clr SI set AA xf break AO case 20 STOP or REP START received while addressed as slave slaveStatus SLAVE_READY SCON RELEASE_BUS_ACK clr SI set AA 7 break BO case 22 Arb lost as MST addressed as slave transmitter slaveStatus SLAVE_BUSY count 0 SDAT slaveBuf count Transmit next data restart x SCON RELEASE BUS STA MST mode if bus is free again break A8 case 21 Addressed as slave transmitter slaveStatus SLAVE BUSY count 0 B8 case 23 Data transmitted ACK received XJ SDAT slaveBuf count Transmit next data x SCON RELEASE BUS ACK clr SI set AA break CO case 24 Data transmitted NOT ACK received slaveStatus SLAVE_TRX_ERROR C8 case 25 SCON RELEASE_BUS_ACK clr SI set AA y break 28 AN94078 Philips Semiconductors P90CL301 I C driver routines void I2C_InitializeSlave BYTE slv BYTE buf BYTE size TKR I ok kok RK k kok k kok k kok k kok k kok k kok k kok RK Input s slv Own slave address buf Pointe
27. SE_BUS_ACK clr STO STA SI and set AA break case 3 SLA W or DATA transmitted ACK received case 5 DATA or STOP will be transmitted if dataCount lt msg gt nrBytes SDAT msg gt buf dataCount sent first byte SCON RELEASE_BUS_ACK clr STA SI else if msgCount lt tfr gt nrMessages dataCount 0 msg tfr gt p_message msgCount next message SCON RELEASE_BUS_STA generate rep START else SCON GENERATE_STOP readyProc I2C_OK msgCount break case 4 case 9 SLA W R transmitted NOT ACK received readyProc I2C NACK ON ADDRESS msgCount driver finished SCON GENERATE STOP break case 6 DATA transmitted NOT ACK received readyProc I2C NACK ON DATA msgCount SCON GENERATE STOP break case 7 Arbitration lost in SLA4W or DATA SCON RELEASE BUS STA release bus set STA break case 8 SLA R transmitted ACK received if msg gt nrBytes 1 SCON RELEASE BUS NOACK No ack on next byte else SCON RELEASE BUS ACK ACK on next byte break case 10 DATA received ACK has been returned msg gt buf dataCount SDAT read next data if dataCount 1 msg gt nrBytes next byte the last SCON RELEASE_BUS_NOACK No ack on next byte else SCON RELEASE_BUS_ACK return ACK break case 11 DATA received NOT ACK has been returned msg gt buf dataCount SDAT read last data if msgCount lt
28. WORD reg struct BYTE dummy 5 BYTE pclk2 1 per clock FCLK2 prescaler BYTE pde 1 A22 19 as 8051 chip selects BYTE gf 1 general purpose flag bit BYTE pclk 25 per clock FCLK prescaler BYTE im T nested interrupt mode x BYTE wd I bus cycle watch dog time out BYTE fbc 1 fast bus cycle BYTE pd 1 power down mode BYTE idl 1 idle mode BYTE doff m delay counter off b SYSCON_TYPE 35 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 X M Register Bit Definitions SCONx Uart0 and 1 X ucc xL LER em K typedef union BYTE reg struct BYTE SM 3 BYTE REN 1 BYTE TB8 1 BYTE RB8 15 BYTE TI il BYTE RI d b SCONX TYPE p n ee BE SYSTEM STATUS amp CONTROL nA bem A o define SYSCON SYSCON TYPE OxFFFF8000 system control register r E ESSE JE EXTERNAL LATCHED INTERRUPTS xy M X o m defi
29. arameters Must be called once after RESET BYTE ownAdress Micro controller s own slave address BYTE buf Pointer to buffer to transmit data from or receive data in BYTE size Size of buffer to transmit data from or receive data in void I2C_Installinterrupt BYTE intLevel Install the 12C interrupt using the specified priority Must be called once after one of the initialization functions is called BYTE intLevel Interrupt level priority of the I C interface In addition to the installation of the 12C interrupt the user has to install the interrupt vector This vector is a pointer to the interrupt routine and must be placed in the interrupt vector table This table can be located in RAM or ROM The interrupt function prototype is given in the file I2CEXPRT H See file EXAMPLE C for an example of initializing a vector in a RAM table Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 void I2C Transfer I2C TRANSFER p void proc BYTE status BYTE msgsDone Start a synchronous I C transfer When the transfer is completed with or without an error call the function proc passing the transfer status and the number of messages successfully transferred 12C_ TRANSFER p void proc status msgsDone BYTE msgsDone BYTE status void I2C_ProcessSlave void A pointer to the structure describing the IC messages to be transferred A pointer to the function to be called when the transfer is com
30. ation Note AN94078 el check if one second is passed
31. ces while retaining bus mastership Stop and repeated start conditions can only be generated in master mode Data and addresses are transferred in eight bit bytes starting with the most significant bit During the 9th clock pulse following the data byte the receiver must send an acknowledge bit to the transmitter The clock speed is normally 100 KHz Clock pulses may be stretched for timing causes by the slave A start condition is always followed by a 7 bits slave address and a R W direction bit In a multi master system arbitration is done automatically by the IC hardware Arbitration can carry on through many bits it can even continue into the comparison of data bytes If arbitration is lost this driver switches to slave mode and automatically back to master mode retry after the slave transfer is done General format and explanation of an IPC message S SLV_W A SUB A un SLV R A DI A D2 A A Dn NP S re Start condition A Acknowledge on last byte N No Acknowledge on last byte P Stop condition SLV W Slave address and Write bit SLV R Slave address and Read bit SUB Sub address D1 Dn Block of data bytes also D1 1 D1 m First block of data bytes Dn 1 Dn m ny block of data bytes Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 2 2 Input definition Inputs application s view to the
32. e AN94078 5 Slave operation The slave mode protocol is very specific to the system design and therefore very difficult to make generic In this report basic slave receive and slave transmit routines are given but they only should be considered as examples To activate the slave mode driver call the function I2C_InitializeSlave see also section 3 2 All slave routines are placed together in the module I2CSLAVE C this module is listed in appendix III There are two ways for the driver to enter the slave functions Through a normal PC interrupt or polling the slave when the driver is idle in slave receiver mode and the interface recognizes its own slave address or a general call address Through master mode during transmission of a slave address in master mode arbitration is lost to another master The driver must then switch to slave receiver mode to check if this other master wants to address him The slave routines as given make use of a single data buffer This buffer pointer and size is initialized during the I2C InitializeSlave function When addressed as slave transmitter bytes from the data buffer are transmitted until a NACK No Acknowledge or a stop condition is received When addressed as slave receiver bytes from the I C bus are received into the data buffer until it is full size is reached The transmission is stopped by the driver by giving no acknowledge on the last data byte After a slave transf
33. e in interrupt driven mode the I2C_Installlnterrupt function must be called after initialization Furthermore the user has to put a vector in the interrupt vector table can be in RAM or ROM This vector is a pointer to the interrupt routine called I2C_Interrupt The user also has to determine the priority level of the interrupt If a transfer is started now the driver interface function returns immediately At the end of the transfer polled or interrupt driven together with the generate stop condition the driver calls a function that was given by the application at the time the transfer was applied for It s up to the user to write this function and to determine the actions that have to be done see example I2CINTFC C 2 6 Using an operating system If you want to use this driver together with a multi tasking real time operating system like pSOS you only have to write or adjust the interface file I2CINTFC C I2CDRIVR C remains unchanged At the place in the interface software where the driver program is called operating system calls have to be used Examples of these calls are wait for set semaphore or send receive mail program time outs etc This way other tasks in your system will not be blocked 2 7 Error handling Normally before sending or receiving a message using an I O driver a time out is programmed Main reason for these time outs is to locate hardware failures like break in the cable remote sys
34. er the application must service the slave i e process received data or put new data in the buffer This is very application dependent therefore the example function I2C_ProcessSlave must be customized by the user Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 6 Modelling hierarchy This lC driver consists of 3 parts Driver software Initialization Master functions Slave functions Interface functions External application interface to the driver An application example running on the Microcore 5 is a P90CL301 evaluation tool The driver package contains the following files I2CDRIVR C The general driver needed for both master and slave features containing the interrupt installation and handler Always link this module to your application I2CMASTR C The actual driver for master transfers containing initialization and master state handling Only needed if your P90CL301 acts as a bus master I2CSLAVE C The actual driver functions needed for the micro to act as a slave on the bus containing initialization and state handling I2CDRIVR H This module include file contains definitions of local data types and constants and is used only by the driver package I2CINTFC C This module contains example application interface functions to perform a master transfer In this module some often used message protocols are implemented Furthermore it shows examples of error handling like
35. ines Application Note AN94078 void I2C_ReadRepRead I2C_MESSAGE msgl I2C_MESSAGE msg2 NER U RR Input s msgl first I C message msg2 second I C message Returns None Description Two messages are read from two different slave devices d separated by a repeated start condition PROTOCOL lt S gt lt Slv1lA gt lt R gt lt A gt lt D1 gt lt A gt lt Dnum1 gt lt N gt lt S gt lt Slv2A gt lt R gt lt A gt lt D1 gt lt A gt lt Dnum2 gt lt N gt lt P gt DE k kok ke kok ok kok k kok oko ROO ROO ko kok kok ok kok ok kok k ROO kok k kok k kok k kok k kok k kok k kok k kok k kok KK Ak I iicTfr nrMessages 2 iicTfr p message p iicMsg p iicMsg 0 msgl p iicMsg 1 msg2 StartTransfer void I2C_ReadRepWrite I2C_MESSAGE msgl I2C_MESSAGE msg2 ok ok kok RK RK k kok k kok k kok k kok k kok k kok k kok R k Input s msgl first I C message msg2 second I C message Returns None Description A block data is received from a slave device and also bi a nother block data is send to another slave device both blocks are separated by a repeated start PROTOCOL lt S gt lt Slv1lA gt lt R gt lt A gt lt D1 gt lt A gt lt Dnum1 gt lt N gt lt S gt lt Slv2A gt lt W gt lt A gt lt D1 gt lt A gt lt Dnum2 gt lt A gt lt P gt Sk kok k kok o kok ok kok k kok oko ok ok ko kok kok ko kok kok oko kok o kok kok k kok k kok k kok k kok k kok k kok k kok
36. l register define BREGL BYTE AT OxFFFF860B UART baud rate register LSB define BREGH BYTE AT OxFFFF860D UART baud rate register MSB define BCON BYTE AT OxFFFF860F UART baud rate control reg c PERIPHERAL INTERRUPT REGISTERS CE define PICRO BYTE AT OxFFFF8701 Timer interrupt register f define PICR1 BYTE AT OxFFFF8703 UARTO interrupt register Hf define PICR2 BYTE AT OxFFFF8705 UART1 interrupt register define PICR3 BYTE_AT 0xFFFF8707 I2C ADC interrupt register p Se et a A A A A O PULSE WIDTH MODULATION REGISTER ne ee a E MER RE he a EET RE A nn E define PWMP BYTE AT OxFFFF8801 PWM prescaler register define PWMO BYTE AT 0xFFFF8803 PWMO data register x define PWM1 BYTE AT OxFFFF8805 PWM1 data register x Etc xc CRETAE LT 3 y ADC REGISTER P R define ADCON BYTE AT OxFFFF8807 ADC control register T define ADCDAT BYTE AT OxFFFF8809 ADC data register E ET WU EU TQ ELE m A E 6 n A E E I mE m En CHIP SELECT REGISTERS ase S o E ae Zn an SE Uses Hasen ee a Se Zen Sans Szenen define CSON WORD AT OxFFFF8A00 chip select 0 control
37. ne LIRO BYTE AT OxFFFF8101 Latched Interrupt 0 1 register define LIR1 BYTE_AT OxFFFF8103 Latched Interrupt 2 3 register define LIR2 BYTE_AT OxFFFF8105 Latched Interrupt 4 5 register define LIR3 BYTE_AT OxFFFF8107 Latched Interrupt 6 7 register A k fo n a a ees 12C ICE L E S EE define SDAT BYTE_AT OxFFFF8201 I2C Data Register define SADR BYTE_AT OxFFFF8203 I2C Address Register define SSTA BYTE AT OxFFFF8205 I2C Status Register x define SCON BYTE_AT OxFFFF8207 I2C Control Register een magenta TIMERS xy M ee r r he A define TOCR WORD AT 0xFFFF8300 Timer 0 control register Ex A define TORR WORD AT OxFFFF8302 Timer 0 reload register pA define TO WORD_AT OxFFFF8304 Timer 0 register E define TOCO WORD_AT OxFFFF8306 Timer 0 channel 0 register define TOC1 WORD_AT 0xFFFF8308 Timer 0 channel 1 register define TOC2 WORD AT OxFFFF830A Timer 0 channel 2 register define TOSR BYTE AT OxFFFF830D Timer 0 status register define TOPR BYTE AT OxFFFF830F Timer 0 prescaler reload reg define TICR WORD_AT OxFFFF8310 Timer 1 control register Ri define TIRR WORD_AT OxFFFF8312 Timer 1 reload register define T1 WORD AT OxFFFF 8314 Timer 1 register define T1CO WORD_AT 0xFFFF8316 Timer 1 channel 0 register E define T1C1 WORD_AT 0xFF
38. ne SLAVE BUSY 1 define SLAVE READY 2 define SLAVE TRX ERROR 3 define SLAVE RCV ERROR 4 Immediate data to write into SCON CR2 CR1 CRO 000 change these values and recompile module i2cdrivr c if a different xy PE bus speed is needed define GENERATE_STOP 0x54 define RELEASE_BUS_ACK 0x44 define RELEASE_BUS_NOACK 0x40 define RELEASE_BUS_STA 0x64 3 LOCAL FUNCTION PROTOTYPES es Se Sa SS pps een Sp ee See e f static void NolnitErrorProc void H k y 8 GLOBAL FUNCTION PROTOTYPES x extern void MainStateHandler void extern void I2C_Transfer I2C_TRANSFER p void proc BYTE BYTE 34 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 APPENDIX VII REG90301 H KKK I RK Ok kok k oko k kok k kok k kok k kok k kok k kok k kok k kok RR Acronym GENERAL Name of module REG90301 H x f 12na SXXXX XXX XXXX X Creation date 1992 11 09 s Program language C x Name P H Seerden T kJ JE Copyright C Philips Semiconductors B V Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands eL x All rights are reserved Reproduction in whole or in part is prohibited without the written consent of the copyright owner S EEK K KK k k KK 2 2 k k k k k 2 2 2 2 2 2 2 2 2 2
39. odule consists a number of exported declarations of the I2C driver package Include this module in your source file if you want to make use of one of the interface functions of the package ER i BRR RR KKK KK 2 2 2 22 22 ok ok 2 2 2222 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2222 k d History E 92 12 10 P H Seerden Initial version Le x ag BRR RR ok ok KK 2 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 RA 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2222 2 2 2073 define FALSE 0 define TRUE 1 BRK RK ok ok KK KK KKK ok ok 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2222 IE EXPORTED DATA STRUCTURES y BRK oko ok ok KK KK 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 22 f define NULL void 0 a null pointer el typedef unsigned char BYTE typedef unsigned short WORD typedef unsigned long LONG typedef struct BYTE address slave address to sent receive message E BYTE nrBytes number of bytes in message buffer BYTE buf pointer to application message buffer El I2C_MESSAGE typedef struct BYTE nrMessages number of message in one transfer I2C_MESSAGE p_message pointer to pointer to message ay I2C_TRANSFER 32 AN94078 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 KK
40. ontroller AY Part of the driver that handles slave bus transfers ey JE Ef BR KKK KK KK k k kok I I KK KK KK k kk kk kk I KK KKK AA I I KK LE xf History P LE 94 08 08 P H Seerden Initial version LE nur 1 s ok k kok ok kok ok oko k kok k kok k kok k kok k kok k kok k kok k kok k kok k kok kok kok k kok kok kok kk kk kk kk kk I AK f include i2cexprt h include i2cdrivr h include reg90301 h extern void slaveProc static BYTE count bytes send received of current message El static BYTE slaveBuf ptr to rec trm data into from if slave static BYTE size size of slave mode buffer static BYTE slaveStatus status of the slave 27 AN94078 Philips Semiconductors P90CL301 IC driver routines void HandleSlaveState void ok k kok ok kok k kok k oko RK Input s none Output s none Returns none Description State handler for I2C Application Note LEE EEE ok kok ok kok ok kok AR RO ROO ROO oko kok ko kok kok ok kok k ROO ROO kok k kok k RR kok k kok k kok k kok k kok RA switch SSTA gt gt 3 gt gt 3 for faster code 8 60 case 12 68 case 13 Addressed as slave 70 case 14 78 case 15 slaveStatus SLAVE_BUSY count 0 if size gt 1 SCON RELEASE_BUS_ACK return ACK on first byte E else SCON RELEASE BUS N
41. ot guarantee that this I C driver is flawless in all applications This application note with C source files is available for downloading from the PHIBBS Philips Bulletin Board System It is packed in the self extracting PC DOS file 12C90301 EXE The system is open to all callers operates 24 hours a day and can be accessed with modems up to 9600 baud The BBS can be reached via telephone number 31 40 721102 Used references The I2C bus specification 9398 358 10011 The I2C bus and how to use it 9398 393 4001 1 P90CL301 Objective Specification JUN 94 2C driver routines for SCC68070 and 9xC10x microcontrollers EIE AN93001 12C driver routines for the 90CE201 microcontroller EIE AN93002 Used development and test tools Microtec MCC68k C compiler version 4 21 Philips Microcore 5 P90CL301 evaluation board OM5040 Philips I2C bus evaluation board OM1016 Philips Logic Analyzer PM3580 PM3585 with 12C bus support package PF8681 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 2 Functional description 2 1 The I C bus format An l C transfer is initiated with the generation of a start condition The condition will set the bus busy An IC message may be followed either by a stop condition or a repeated start condition A stop condition will release the bus mastership A repeated start offers the possibility to send receive more than one message to from the same or different devi
42. pleted Number of message successfully transferred one of l2C OK Transfer ended No Errors I2C BUSY IPC busy so wait 12C_ERR General error 12C_NO_DATA err No data message block 12 NACK ON DATA err No ack on data in block I2C NACK ON ADDRESS err No ack of slave I2C DEVICE NOT PRESENT err Device not present l2C ARBITRATION LOST err Arbitration lost l2C TIME OUT err Time out occurred I2C SLAVE ERROR Slave mode error I2C INIT ERROR err Initialization not done This function can be used by the application to handle slave transfers It is just an example and should be customized by the user Depending of the status of the slave it takes action Possible slave states are SLAVE IDLE SLAVE BUSY SLAVE READY SLAVE TRX ERROR SLAVE RCV ERROR Slave is idle Transfer busy Slave transfer done Transmit data error Receive data error Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 3 3 Interface layer example The module I2CINTFC C gives an example of how to implement a few basic transfer functions see also previous PCALE I C driver application notes These functions allow you to communicate with most of the available I2C devices and serve as a layer between your application and the driver software This layered approach allows support for new devices micro controllers without re writing the high level device independent code The given examples are void I2C Write I2C MESSAGE msg
43. r to slave data buffer a size size of the slave data buffer Output s None Returns None Description Enable I C slave bus and set the clock speed for I C Application Note AN94078 Skok k kok ok kok ok kok k kok oko k k kok k kok kok ko kok kok ok kok k kok 2 22 kok k kok k kok k kok k kok k kok k kok k k kk kok KK f slaveProc HandleSlaveState slaveStatus SLAVE IDLE slaveBuf buf size size PCON 0x0C set alternate I O port function to I C SADR slv own slave address SCON RELEASE BUS ACK set speed and enable I C hardware void I2C ProcessSlave void RK KKK ok k k ke 2 2 k k k oko k k k k k k k Input s None Output s None Returns None Description Process the slave This function must be called by the application to check 5 the slave status The USER should adapt this function to his personal needs take the right action at a certain status DEE k kok ok kok ok kok k ROO ROO ROO ROO ROO ROO ROO ROO 2 22 2 ko 2 k kok k kok k kok k kok k kok k kok kok KK eee switch slaveStatus case SLAVE_IDLE do nothing or fill transmit buffer for transfer break case SLAVE_BUSY do nothing if interrupt driven if PICR3 amp 0x70 else poll SCON SI bit level 0 gt polling if SCON amp 0x08 MainStateHandler wait until SI kit is set break case SLAVE_READY read or fill buffer for next transfer slaveStatu
44. s SLAVE_IDLE break case SLAVE_TRX_ERROR generate error message slaveStatus SLAVE_IDLE break case SLAVE_RCV_ERROR generate error message slaveStatus SLAVE_IDLE break signal application 29 El xj l xy E Ld s Philips Semiconductors P90CL301 IC driver routines Application Note APPENDIX IV I2CDRIVR C KR KR RK k ok k kok k kok k kok k KC ROO k kok k kok k RR Acronym I C Inter IC bus for P90CL301 Name of module I2CDRIVR C el Scope Universal I C driver 12nc i KXXX XXX XXXX X Creation date 1994 08 08 Program language C Name P H Seerden Ef Z LE XJ C Copyright 1994 Philips Semiconductors B V ig Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 LE El All rights are reserved Reproduction in whole or in part is prohibited without the written consent of the copyright owner JE x BRK KK KKK ok 2 22 22 2 2 2 2 2222 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 IE 2 2222 2 2 2073 Description LE JR Driver for the I C hardware interface on the Philips P90CL301 microcontroller xy es Main part of the driver Contains the interrupt handler and does calls to the master and or slave driver part BRR RK ok ok KK KK 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 kok ok 2 2 2 2 2 2
45. tem not responding or interface hardware failure However to program a time out a hardware timer or an operating system is needed Therefore the driver package does not support these time outs too much application and system environment dependent Also message retries are not supported by the driver because they often happen simultaneously with time outs Nevertheless the example given in this report shows you how to simply add retries and time outs software loops to your driver interface see I2CINTFC C Furthermore a status error is passed every time the transfer ready function is called by the driver It s up to the user to handle possible errors Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 3 External application interface This section specifies the external interface of the driver towards the application The C coded external interface definitions are in the include file I2CEXPRT H The application s view on the IC bus is quite simple The application can send messages to an IC device Moreover the application must be able to exchange a group of messages optionally addressed to different devices without losing bus mastership Retaining the bus is needed to guarantee atomic operations 3 1 External data interface All parameters affected by an l C master transfer are logically grouped within two data structures The user fills these structures and then calls the interface func
46. ter block x untouched until the ready procedure is called The first I C message is started with sending a start k condition followed by the slave address Sk kok k kok o kok ok kok k kok oko kok ko kok ko kok kok ok kok ok kok ok kok kok k kok k kok k kok k kok k kok k kok k kok k kok kok KR I f tfr p readyProc proc msgCount 0 dataCount 0 msg tfr gt p message msgCount first message to send SCON RELEASE_BUS_STA generate START condition 26 Philips Semiconductors P90CL301 IC driver routines Application Note APPENDIX Ill I2CSLAVE C TK RK I RK ok kok k oko k kok k kok k kok k kok k kok k kok k kok k kok RR Acronym I C Inter IC bus for P90CL301 ay Name of module I2CSLAVE C xy Scope Universal I C driver 12nc 3 XXXX XXX XXXX X Creation date 1994 08 08 Program language C Name P H Seerden JE Jp 7 C Copyright 1994 Philips Semiconductors B V yE Product Concept amp Application Laboratory Eindhoven PCALE Eindhoven The Netherlands 5 JD x All rights are reserved Reproduction in whole or in part is x prohibited without the written consent of the copyright owner LE EJ EEE 3 2 2 22 22 2 2 ok oko oko ok 2 2 2 2 2 2 2 2 2 22 2 2 2 22 22 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 kkk kk ui Description LE i JE Driver for the I C hardware interface on the Philips P90CL301 x microc
47. tfr gt nrMessages dataCount 0 msg tfr gt p_message msgCount SCON RELEASE_BUS_STA else next message generate rep START SCON GENERATE_STOP readyProc I2C OK msgCount 25 f XA i x x El sy RY ey v Sf x7 Rf El ip El El ur f 7 Application Note AN94078 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 void I2C_InitializeMaster void KKK IKK k k k kk IK RK Input s None Output s None Returns None Description Enable I C bus and set the clock speed for I C RRR ok kok k kok ok 2 ok 2 o kok ok kok ok kok kok ROO ROO ROO ROO kok k kok k ARR k kok RRA I ZZ masterProc HandleMasterState PCON 0x0C set alternate I O port function to I C SADR 0x26 set default slave address SCON RELEASE_BUS_ACK set speed and enable I C hardware S void I2C Transfer I2C TRANSFER p void proc BYTE BYTE BRK KKK RAR ok ok oko RR KA RR 2 2 2 22 2 ok 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 KARA Input s B address of I C transfer parameter block proc procedure to call when transfer completed E with the driver status and the nr of mesgs passed as parameters Output s None Returns None Description Start an I C transfer containing 1 or more messages The x application must leave the transfer parame
48. tion to perform a transfer The data structures used are listed below typedef struct BYTE nrMessages total number of messages 12C_ MESSAGE p_message ptr to array of ptrs to message parameter blocks E l2C TRANSFER The structure I2C TRANSFER contains the common parameters for an I C transfer The driver keeps a local copy of these parameters and leaves the contents of the structure unchanged So in many applications the structure only needs to be filled once After finishing the actual transfer a transfer ready function is called The driver status and the number of messages done are passed to this function The structure contains a pointer p message to an array with pointers to the structure I2C MESSAGE shown below typedef struct BYTE address The PC slave device address BYTE nrBytes number of bytes to read or write i BYTE buf pointer to data array 12C_MESSAGE Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 The direction of the transfer read or write is determined by the lowest bit ofthe slave address write 0 and read 1 This bit must be re set by the application The array buf must contain data supplied by the application in case of a write transfer The user should notice that checking to ensure that the buffer pointed to by bufis at least nrBytes in length cannot be done by the driver Otherwise the array is filled by the driver If
49. ustrial or intellectual property rights Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 APPLICATION NOTE P90CL301 IC driver routines AN94078 Author s Paul Seerden Product Concept amp Application Laboratory Eindhoven The Netherlands Keywords Microcontroller P90CL301 Driver routines Application software FC bus multi Master Slave Date 1st November 1994 Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 Summary This application note shows how to write an Inter Integrated Circuit bus driver I2C for the Philips P90CL301 micro controller It is not only an example of writing a driver but it also includes a set of application interface software routines to quickly implement a complete I2C multi master system application For specific applications the user will have to make minimal changes in the driver program Using the driver means linking modules to your application software and including a header file into the application source programs A small example program of how to use the driver is listed The driver supports i a polled or interrupt driven message handling slave message transfers and multi master System applications Furthermore it is made suitable for use in conjunction with real time operating systems like pSOS Philips Semiconductors P90CL301 l C driver routines Application Note AN94078 CONTENTS 1 INTOCUCION zer
50. you want to use bufas a string a terminating NULL should be added at the end It is the users responsibility to ensure that the buffer pointed to by bufis large enough to receive nrBytes bytes 3 2 External function interfaces This section gives a description of each callable interface function in the I2C driver module First the initialization functions are discussed These functions directly program the I C interface hardware and are part of the low level driver software They must be called only once after reset but before any transfer function is executed The driver contains the following three functions 12C_InitializeMaster in file I2CMASTR C 12C_InitializeSlave in file IACSLAVE C 12C_Installinterrupt in file I2CDRIVR C Next two functions to perform transfers will be discussed 12C_Transfer in file I2CMASTR C 12C_ ProcessSlave in file I2CSLAVE C Philips Semiconductors P90CL301 IC driver routines Application Note AN94078 void I2C_InitializeMaster void Initialize the 12C bus master driver part Hardware IC registers of the P90CL301 interface will be programmed Used constants parameters are defined in the file IACDRIVR H Must be called once after RESET before any other interface function is called void I2C InitializeSlave BYTE ownAddress BYTE buf BYTE size Initialize the I C bus slave driver part Hardware I C registers of the P90CL301 interface will be programmed with the designated p
Download Pdf Manuals
Related Search
Related Contents
Gerador Síncrono 取扱説明書 - 瀧住電機工業株式会社 SEFRAM 9861 Humidimètre à LED Manuel d`utilisation パンフレット AK7シリーズ Kicker 5-Channel Owner's Manual SilenPlus ControlSystem 取扱説明書等 Guide de l`utilisateur Copyright © All rights reserved.
Failed to retrieve file