Home
ST7 software library
Contents
1. For testing only 3 Function Descriptions A A A a SS ROUTINE NAME TIMER8_IT_Routine INPUT None OUTPUT None DESCRIPTION Interrupt service routine COMMENTS This gets automatically executed when any of the timer8 interrupt is enabled If the same functions are called in the main Tree and the interrupt Tree the function Re entrant error occurs in case COSMIC compiler is used with models other than stack models For configuring the port pins I O library is used Sa aoa coo a ls o as ifdef _HIWARE_ Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved telse ifdef _COSMIC_ Test for Cosmic Compiler interrupt else terror Unsupported Compiler Compiler Defines not found endif endif void TIMER8_IT_Routine void unsigned int CAP2_Value Define local variables unsigned char i Temp if T8CSR amp 0x10 f TIMER8_Status_Flag TIMER8_FLAG_1CF2 TRUE Call to Check ICF2 Temp T8CSR Clear ICF2 Temp T8IC2R TIMER8_Clear_Flag TIMER8_FLAG ICF2 Call to clear ICF2 call to get capture value and also clear ICF2 CAP2 Value TIMER8_ICAP_Getvalue TIMER8_ICAP_2 Port PAO pushpull output IO Output IO PUSH PULL IO PORT A IO PIN 0 IO Write IO PORT A IO PIN 0 IO DATA HIGH Port PAO made high for i 0 i lt 250 i Delay Nop IO Write IO PORT A IO PIN 0 IO DATA
2. TTA 99 235 Function Descriptions BOOL User Timeout Function void Prototypes of user function void User_Function void Declaration of all global variables used in main c define size_buff unsigned char 0x0A define My Data unsigned char 0x55 define Addr Byte Tx unsigned char 0xA0 define Sub Byte Tx unsigned char 0x50 static unsigned int Timeoutcount endif F 55 777555555 5555555555557775755555 Program Start include ST71ib_config h List of all ST7 devices and communication mode include main h Declaration of prototypes of user defined functions used in main c void main void unsigned char Rx_Data unsigned char Buff_Test size_buff unsigned char Buff size buff 0 1 2 5 50 10 100 200 225 255 12C_TxErrCode_t Templ 12C_RxErrCode_t Temp2 Templ Temp2 0x00 I2C Init unsigned char 12C_ENABLE_ACK unsigned char I2C IT ENABLE Enable acknowledge and interrupts EnableInterrupts Interrupt mask is reset for enabling interrupt 12C_MultiMaster_Config Configure I2C as multimaster I2C device I2C_Select_Speed I2C FASTSPEED unsigned int 200 Selects fast speed mode Speed is 200KHz I2C Generate Start while 12C_IsTransmitCompleted I2C START OK o ooooooooooooooooooooooooooo Transmission through Polling mode
3. Required Preconditions Functions called None None Postconditions See also If you want to enable the SPI output again you must call SPI Init and pass the SPI_DEFAULT parameter SPI Init 60 235 3 Function Descriptions Table 30 SPI_PutByte Function Name Function Prototype SPI_PutByte Void SPI_PutByte unsigned char Tx_Data Behaviour Description Input Parameters Output Parameters Transmits a single byte of data in SPI Polling or SPI Inter rupt driven modes Tx_Data Data byte to be transmitted None Required Preconditions 1 SPI should be configured correctly 2 You must define the Transmission mode SPI Polling or SPI Interrupt driven 3 You must enable interrupts for SPI Interrupt driven mode 4 For SPI Interrupt driven mode SPI IsTransmitCompleted must have been called to en sure that there are no pending reguests 5 For SPI Interrupt driven mode SPI IT Function must have been called in the Interrupt service routine Functions called Postconditions None Call SPI IsTransmitCompleted after this function to get the transmission status See also Notes SPI IsTransmitCompleted The above function is only for SPI Polling or SPI Interrupt driven modes It is recommended to add timeout protection when using this function For transmission in software slave mode you must define SPI SLAVE CONFIG in ST7lib_config
4. This function may affect other functions as it changes the clock source which will also affect the LiteTimer Input capture functionality because this is used along with LART Input Capture for this mode 3 183 235 Function Descriptions Table 131 LART_LonglCAPGetValue Function Name Function Prototype LART_LongiCAPGetValue Void LART_LonglCAPGetValue unsigned char LTVal ue unsigned int LARTValue Behaviour Description Input Parameter Output Parameters Required Preconditions Enables the long input capture function of LART This function selects clock source as Lite Timer output Input capture source as Lite Timer input capture and interrupt source as specified in InitParams None Parameters are passed as reference to get the out put results LTValue Value of Lite Timer Input Capture register LARTValue Value of LART Input Capture register LART_LonglCAPMode should be called to configure long Input Capture mode Input Capture event must occur be fore this function call Functions called Postconditions None Input capture flags of Lite Timer and LART are cleared See also LART_LonglCAPGetValue Note This function is available only for the ST7FLite3 device Table 132 LART_GenerateDeadTime Function Name LART_GenerateDeadTime Function Prototype Behaviour Description Void LART_GenerateDeadTime unsigned char DT Value This function generates a dead ti
5. Notes The above function is for SPI Polling and SPI Interrupt driven modes In SPI Polling mode this function is called only after SPI PutByte function 66 235 Y Function Descriptions Table 36 SPI_GetByte Function Name SPI_GetByte Function Prototype Unsigned char SPI_GetByte void Returns the most recent Byte received in SPI Polling or SPI Interrupt driven mode Input Parameters None Unsigned char Returns the received data byte 1 The SPI should be configured correctly 2 You must define SPI Polling or SPI Interrupt driven mode in ST7lib_config h 3 You must enable interrupts for SPI Interrupt driven mode Required Preconditions 4 In both SPI Polling and SPI Interrupt driven modes you must call SPI IsReceptionCompleted before this function to check the reception status 5 For SPI Interrupt driven mode SPI_IT_Function must have been called in the Interrupt service routine Functions called None Postconditions None See also SPI IsReceptionCompleted Notes The above function is for SPI Polling or SPI Interrupt driven mode Behaviour Description Output Parameters It is recommended to add a timeout protection when using this function Y 67 235 Function Descriptions Table 37 SPI_GetString Function Name Function Prototype SPI_GetString SPI_RxErrCode_t SPI GetString unsigned char PtrTo String Behaviour Description
6. RRR KK KKK KKK END OF INTERRUPT DRIVEN MODE k k k k k END OF RECEIVER ROUTINE 122 235 3 Function Descriptions FERRERA RARE RE K KA RE RE K KA K K K A K KK RR K A KKK K RR A KA K K RRE RRE RE RE KR COMPARE THE TRANSMITTED AND RECEIVED BYTES while single byte first byte for i 0 i lt maxsize i addbraces while Buff Out i Buff In i RRR RRR RR ERK KERR KA K KEK KER IAN while 1 End of the main eS 5 r Sr l Se m bm OE eee SS E m ROUTINE NAME User IT Routine INPUT None OUTPUT None DESCRIPTION Control comes into this routine when an interrupt is generated User can use the I2C interrupt service routine function for slave or he can write his own code inside this routine at his own risk The data transfer syncronisation may be affected if user includes his own code along with 12C ISR function COMMENTS None a L Zo E m S o S S lt A ey A A a A A SL a o S E ifdef _HIWARE_ Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved else Hifdef _COSMIC_ Test for Cosmic Compiler interrupt Cosmic interrupt handling else error Unsupported Compiler Compiler Defines not found endif endif void I2Cs User IT Routine void I2Cs ITFunction FERRERA RARE RE RARE K K K K K KA KK KEKE EK KK RK KE KKK RK KEK KA K KR KEKE kkk KEK
7. TBU_SetPrescCount16 187 235 Function Descriptions Table 134 TBU_SetPrescCount16 Function Name Function Prototype TBU_SetPrescCount16 Void TBU_SetPrescCount16 TBU_CasPresc TBU_CasPrescvalue_P unsigned int Counter_Value Behaviour Description Input Parameters Input Parameters Selects the prescalar value for the PWMART timer and the counter values to be loaded into the TBU and ART regis ters ART counter is enabled TBU_CasPrescvalue_P where P is the prescalar division factor and it can be 1 2 4 8 16 32 64 128 Counter_value 16 bit counter value This value can be from 0000 to FFFFh Output Parameters Reguired Preconditions None 1 TBU Init must have been called 2 Cascaded mode must be selected 3 You must calculate the TBU CasPrescValue P and Counter Value for the reguired delay Functions called Postconditions TBU Enable must be called immediately after this func tion to get more accurate delay None See also Notes TBU_SetPrescCount8 The actual delay obtained using this function will be approximately equal to the calculated delay For best accuracy and smaller delays it is recommended to use the TBU_SetPrescCount8 function 188 235 3 Function Descriptions Table 135 TBU_Enable Function Name Function Prototype TBU_Enable Void TBU_Enable void Behaviour Description Input Parameters TBU is enabled
8. Table 13 SCIx PutByte Function Name SCIx_PutByte Function Prototype Void SCIx_PutByte unsigned char Tx_Data Behaviour Description Transmits a single byte of data polling mode or interrupt driven mode Input Parameters Tx Data Data byte to be transmit Output Parameters None 1 SCIx_Mode must have been called 2 SClx_IsTransmitCompleted must have been called Refer to example on page 53 for more details 3 You must enable the interrupt due to Transmit Com plete Transmit Data Ready Flag for the Interrupt driven mode 4 You must select Polling or Interrupt driven Transmis sion mode in ST7lib_config h Required Preconditions Functions called None Postconditions None See also None Notes You can use some timeout protection while using this function This function is for Polling or Interrupt driven mode Table 14 SCIx_IsTransmitCompleted Function Name SCIx IsTransmitCompleted Function Prototype BOOL SCIx IsTransmitCompleted void Checks for the completion of current byte transmission Behaviour Description Returns TRUE if byte transmission is completed otherwise returns FALSE Input Parameters None Output Parameters Boolean Required Preconditions SCIx_PutByte must have been called Functions called None Postconditions None See also None Note This function is for Polling mode 40 235 3 Function Descriptions Table 15 SCIx PutBuffer
9. Functions called Postconditions None Selected status flag is cleared See also 1 Feature available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI devices LART Status Flag 2 Feature available only on ST7FLite3 device 178 235 3 Function Descriptions Table 123 LART_ICAPMode Function Name Function Prototype LART_ICAPMode Void LART_ICAPMode Lart_ICAPInitParams InitPar ams Behaviour Description Configures the input Capture mode This function also en ables Input capture interrupt if LART ICAP IT ENABLE is passed as user parameter This function clears the input capture flag Input Parameter Output Parameters InitParams LART ICAP DEFAULT Input capture function is used in polled mode LART ICAP IT ENABLE Input Capture Interrupt is enabled None Reguired Preconditions Functions called LART_Init must have been called to select the counter clock None Postconditions Poll Input Capture flag or wait for interrupt to read the Input Capture value See also LART ICAPGetValue Note This function is available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI de vices Table 124 LART_ICAPGetValue Function Name LART_ICAPGetValue Function Prototype Behaviour Description Unsigned int LART_ICAPGetValue Reads the 12 bit Input capture register value Input Parameter Output Parameters None Returns the 12 bit in
10. In case of any mismatch control gets struck ina loop include ST71ib_config h include main h unsigned char Buff_In 9 0x00 unsigned char Buff_Out 1 2 3 4 5 6 7 8 9 void main void This is for polling interrupt driven unsigned char OAR1Value 0x30 unsigned char OAR2Value 0x00 unsigned char maxsize 9 single byte 0x05 first byte 0x00 BOOL TX_STATUS TRUE I2Cs ErrCode t Error Status 12Cs_DEFAULT_STATUS I2Cs Mode Comm Mode I2Cs DEFAULT unsigned int i EnableInterrupts I2Cs Init unsigned char I2Cs ENABLE ACK unsigned char I2Cs_ENABLE_ENGC OAR1Value OAR2Value ACK bit is set 118 235 ky Function Descriptions Error Status I2Cs IsReceptionCompleted while Time Out amp amp Error Status I2Cs ADDRESS DETECTED Time out is bring before to remove side efffect error Error Status I2Cs IsReceptionCompleted Comm Mode I2Cs GetCommMode while Comm Mode I2Cs DEFAULT Comm_Mode 12Cs_GetCommMode checking for communication mode FERRERA RARE RR Polling Mode Transmission KKK KKK RRE RE RE REKO RRRKKRKKKE BUFFER TRANSMISSION EAS RRRKKRKE POLLING MODE RRKKK KKK KKK KK RK KKK KEKE KKK KEKE RR EKRKEKRKEEE 3 if Comm Mode I2Cs TX MODE SINGLE BYTE TRANSMISSION I2Cs_PutByte single_byte Error Status I2Cs IsTransmitCompleted transmitter mo
11. Input Parameters Output Parameters Required Preconditions Functions called Receives the data string in SPI Polling mode and stores itin a user defined area The data reception will stop if any error occurs during reception The reception status will be returned PtrToString Start address of the String SPI_RX_MODF If master mode fault occurs SPI_RX_OVR If overrun condition occurs SPI_RECEIVE_OK If there is no error in reception 1 The SPI must be configured correctly 2 You must define SPI Polling mode in ST7lib config h Postconditions See also SPI GetString SPI Interrupt driven mode Note The above function is only for SPI Polling mode Caution The application can lose control if the SPI is disabled while using this function in poll ing mode Y 68 235 Function Descriptions Table 38 SPI_GetBuffer Function Name SPI GetBuffer SPI RxErrCode t SPI GetBuffer unsigned char PtrTo Buffer unsigned char NbOfBytes Receives a number of data bytes in SPI Polling mode and stores them in a user defined area The data reception will stop if any error occurs during reception The reception status will be returned PtrToBuffer Start address of the user buffer NbOfBytes Number of bytes to be received SPI_RX_MODF If master mode fault occurs SPI_RX_OVR If overrun condition occurs SPI_RECEIVE_OK If there is no error in reception 1 The SPI should be configured cor
12. IO Input IO FLOATING IO PORT B unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char I1O_PIN_6 Initialise the timer with external clock frequency and overflow interrupt enabled PWMART Init unsigned char PWMART_EXCLK unsigned char PWMART_OVF_IT_ENABLE clear I bit in CC register EnableInterrupts Macro defined in st7lib config h Autoload the counter with ARR PWMART Counter Enable PWMART REG ARR Counter Data PWMART CLK 1 Output compare signal on PWM2 pin PWMART OCMP Mode PWMART OCMP 2 PWMART POLARITY O Compare Data To detect rising edge at capturel capturel interrupt enable PWMART ICAP Mode PWMART ICAP 1 unsigned char PWMART SENSITIVITY R unsigned char PWMART ICAP1 IT ENABLE PWM signal on PWM1 pin PWMART PWM Mode PWMART 1 PWMART POLARITY O DutyCycle Data while 1 For testing only ROUTINE NAME PWMART IT Routine INPUT None OUTPUT None DESCRIPTION Interrupt service routine COMMENTS This gets automatically executed when any of the PWMART interrupt is enabled If the same functions are called in the ISA 169 235 Function Descriptions main Tree and the interrupt Tree the function Re entrant error occurs in case COSMIC compiler is used with models other than stack models aaa ias so E a E ia o a a E o pia a Soo oa ajo BONE E ifdef
13. Input Parameters Output Parameters None Required Preconditions Any Interrupts enabled Functions called None Postconditions Interrupts are masked due to a particular flag See also TIMERx_IT_Enable 1 Not available in ST72F65 Note Timer B available in ST72F521 ST72F264 ST72325 and ST7232A TTA 125 235 Function Descriptions Table 79 TIMERx_OCMP_Mode Function Name Function Prototype TIMERx_OCMP_Mode Void TIMERx_OCMP_Mode Timer_Compare CMP un signed int OCR VALUE Timer Olevel OUTPUT L Behaviour Description Input Parameter 1 Input Parameter 2 Input Parameter 3 Configures the timer in Output compare or Forced compare mode depending upon the input parameter passed This function should be called twice in order to get both the com pare mode OCMP1 8 OCMP2 TIMER_OCMP_X X 1 output compare1 mode is selected X 2 output compare2 mode is selected TIMER FORCDCMP Y Y 1 Forced compare 1 is selected Y 2 Forced compare 2 is selected OCR VALUE You can select this value from 0x0000 to OxFFFF TIMER OUTPUT F A low level is reflected at the output compare pin after suc cessful comparison TIMER OUTPUT R A high level is reflected at the output compare pin after suc cessful comparison Output Parameters None Required Preconditions Timer correctly initialized Functions called None Postconditions Timer starts functioning in either of the above select
14. Returns the most recent Byte received in Polling or Inter rupt driven mode None Output Parameters Unsigned char Received data byte Required Preconditions 1 The SCIx_Mode must have been called 2 You must have called SCIx IsReceptionCompleted to check the reception status 3 You must enable the interrupt due to Receive Data Ready flag for Interrupt driven mode 4 You must select Polling or Interrupt driven Reception mode in ST7lib Config h 5 For Interrupt driven mode SCIx IT Function must have been called inside the SCI interrupt subroutine Functions called None Postconditions None See also None Notes You can use some timeout protection while using this function This function can be used in Polling or Interrupt driven mode 44 235 3 Function Descriptions Table 20 SCIx GetBuffer Function Name Function Prototype SCIx GetBuffer SCI RxError tSCIx GetBuffer unsigned char PtrTo Buffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Reguired Preconditions Receives a number of data bytes and stores them in the user buffer The reception stops as soon as an error oc curs and error status is returned The data reception is controlled by polling PtrtoBuffer Start address of the user buffer NbOfBytes Total number of bytes to be received SCI_NOISE_ERR Noise error occurred during tr
15. break while 1 Time Out elapsed without transmission completion Error in communication and user should handle the case ifdef SPI ITDRV WITHOUTBUF RX Single byte reception Temp2 SPI IsReceptionCompleted while User Timeout Function ss Temp2 SPI RX DATA EMPTY Waits for data byte reception Temp2 SPI_TsReceptionCompleted if User_Timeout_Function else switch Temp2 case SPI RX MODF SPI RX OVR case SPI RX MODF case SPI RX OVR User Function Error Management Rx Data SPI GetByte User will get the corrupted data break case SPI RECEIVE OK Reception successful Rx Data SPI GetByte break default If none of the above condition is met User Function break while 1 Time Out elapsed without reception completion Error in communication and user should handle the case Reception of the data in the user buffer SPI_GetBuffer Buff_Test NbOfBytes_get 78 235 Any data received before calling this function is ignored ky Function Descriptions Here user can perform other tasks or operations except reception till the time re ception is complete after which user can perform reception again Temp2 SPI_IsReceptionCompleted while User Timeout Function amp amp Temp2 SPI_RX_BUFFER_ONGOING Temp2 SPI IsReceptionCompleted
16. 3 TIMERx Status Flag TIMERx PWM Mode TIMERx OPM Mode TIMERx_ICAP_Getvalue 127 235 Function Descriptions Table 81 TIMERx_PWM_Mode Function Name Function Prototype TIMERx_PWM_Mode Void TIMERx_PWM_Mode Timer_Olevel OUTPUT1_L Timer_Olevel OUTPUT2_L unsigned int OCR1 VALUE unsigned int OCR2 VALUE Behaviour Description Configures the timer in Pulse width modulation mode It enables the generation of a signal with freguency and duty cycle depending upon input parameters given by user If both PWM and OPM modes are active then only PWM works In PWM mode ICAP1 pin cannot be used for input capture function but ICAP2 can be used Input Parameter 1 TIMER OUTPUT1 F Low level is reflected at the output compare1 pin after suc cessful comparison of output compare register with free running counter TIMER OUTPUT1 R High level is reflected at the output compare1 pin after successful comparison of output compare1 register with free running counter Input Parameter 2 Input Parameter 3 Input Parameter 4 Output Parameters TIMER OUTPUT2 F Low level is reflected at the output compare1 pin after suc cessful comparison of output compare2 register with free running counter TIMER OUTPUT2 R High level is reflected at the output compare1 pin after successful comparison of output compare register with free running counter OC1R VALUE You can select this value from 0x0000 to OxFFFF OC2
17. Function Name Function Prototype SCIx PutBuffer Void SCIx_PutBuffer const unsigned char PtrToBuffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameter Starts transmission from the user buffer The data trans mission will be driven either in Polling or Interrupt driven mode depending on the mode you selected PtrToBuffer Start address of the user buffer NbOfBytes Number of bytes to be transmitted None Required Preconditions Functions called 1 SCIx_Mode must have been called 2 You must enable the interrupt due to Transmit Data Ready Flag for the Interrupt driven mode 3 You must select the Polling or Interrupt driven trans mission mode in ST7lib Config h file 4 The SCIx IT Function must have been called inside the SCI interrupt subroutine SCIx IsTransmitCompleted Postconditions See also None None Note This function is for Polling or Interrupt driven mode Caution The application can lose control if the SCI is disabled while using this function in polling mode Take care not to access the user buffer until transmission is complete 3 41 235 Function Descriptions Table 16 SCIx PutString Function Name SCIx PutString Function Prototype Void SCIx PutString const unsigned char PtrToString Starts transmission of a string passed by the user The Behaviour Description data transmissio
18. Functions called None Postconditions None See also TBU_Enable Table 139 TBU_Disable Function Name TBU_Disable Function Prototype Void TBU_Disable void Behaviour Description Disables the TBU counter and prescaler Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also TBU_Enable Example The following C program shows the use of the TBU functions Program description This program is for an ST2F62 device lt generates an interrupt after 1ms if the TBU_Standalone label is selected in ST7lib config h file or generates an interrupt after 1s if TBU Cascade label is selected in ST7lib_config h file Also an interrupt subroutine is written which clears the interrupt flag KERR RKK K RARA RARA RARA RRA RARA KKK Program Start KRKA KKK KKK A KR K KK K K KKK RE R ERAS example code for tbu ST72F62 device include ST71ib_config h define TBU Standalone Configuration File x 190 235 Function Descriptions void TBU_IT_Routine void void main void void main void unsigned char Counter_Value8 224 unsigned int Counter_Valuel6 10330 unsigned char counter Variable declaration EnableInterrupts Reset the interrupt mask A EE E S A eo ee ea a A A Sia For Stand alone mode a Ss SS o n lt SS SS A Zo DS Lod A me ifdef TBU_Standalone Selects Standalone mode TBU Init TBU DEFAULT TBU IT ENABLE Enable
19. IO_PIN_2 unsigned char IO_PIN_4 ned char IO PIN 5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 L IO PORT E unsigned char IO_PIN_0 IO_PIN_1 unsigned char IO_PIN_2 unsigned char unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 IO Output IO OPEN DRAIN IO PORT F unsigned char IO_PIN_0 unsigned char IO PIN 1 unsigned char IO_PIN_2 unsigned char 3 Function Descriptions 3 IO_PIN_3 unsigned char IO_PIN_4 unsigned char IO PIN 6 unsigned char IO PIN 7 IO Write IO PORT A unsigned char IO PIN 0 unsigned char IO PIN 1 unsigned char IO PIN 2 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO PIN 5 IO DATA HIGH IO Write IO PORT B unsigned char IO PIN 0 unsigned char IO PIN 1 unsigned char IO PIN 2 unsigned char IO PIN 3 unsigned char IO Write IO PORT C unsigned char IO PIN 2 unsigned char IO_PI IO PIN 6 unsigned char IO_PIN_7 IO_DATA_HIGH E31 unsigned char IO PIN 4 unsigned char IO PIN 5 unsigned char IO PIN 6 unsigned char IO_PIN_7 IO_DATA_HIGH IO Write IO PORT D unsigned char IO_PIN_0 unsigned char IO_PIN_1 unsigned char IO_PIN_2 unsigned char IO_PIN_5 unsigned char IO PIN 6 unsigned char IO_PIN_7 IO_DATA_HIGH IO Write
20. Postconditions None None See also I2C GetBuffer I2C Interrupt driven mode This is applicable only in multimaster 12C Notes The above function is only for I2C Polling mode ACK bit is managed automatically inside this routine STOP bit is set automatically inside this routine before the last byte is read So there is no need to calll2C Generate Stop after this Caution The application can lose control if 12C is disabled when using this function in 12C Polling mode 3 93 235 Function Descriptions Table 56 12C_GetBuffer Function Name Function Prototype I2C GetBuffer Void 12C_GetBuffer unsigned char PtrToBuffer un signed char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts reception of data and stores it in user defined area for I2C Interrupt driven mode PtrToBuffer Start address of the user buffer NbOfBytes Number of bytes to be received None Required Preconditions 1 12C Load Address must have been called If 12C is configured in master receiver mode 2 You must define I2C Interrupt driven mode in ST7lib_config h 3 12C_IsReceptionCompleted must have been called to ensure that there are no pending requests 4 You must enable interrupts for this mode 5 In 12C Interrupt driven mode I2C IT Function must have been called in the Interrupt service routine Functions called
21. Software Priority of the current interrupt is at Level2 IT_LEVEL_3 Software Priority of the current interrupt is at Level3 Required Preconditions None Functions called None Postconditions None See also None Note This function is for ST72F521 ST72F561 ST72F65 ST72F62 ST72F264 ST72325 and ST7232A devices x 198 235 Function Descriptions Table 149 ITC_GetPriority Function Name Function Prototype ITC_GetPriority ITC_LEVEL ITC_GetPriority ITC_IT IT Behaviour Description Input Parameter 1 3 Returns the software priority level of the selected interrupt IT MCC Returns the software priority of MCC interrupt IT ElO Returns the software priority of External interrupto IT El1 Returns the software priority of External interrupt1 IT_El2 Returns the software priority of External interrupt2 IT_El3 Returns the software priority of External interrupt3 IT_CAN Returns the software priority of CAN peripheral interrupt IT_SPI Returns the software priority of SPI peripheral interrupt IT_TIMERA Returns the software priority of TIMER A peripheral inter rupt IT_TIMERB Returns the software priority of TIMERB peripheral inter rupt IT SCI Returns the software priority of SCI peripheral interrupt IT AVD Returns the software priority of Auxiliary Voltage detector interrupt 199 235 Function Descriptions IT I2C Returns the software priority of I2C peripheral interrupt IT
22. This function reloads the autoreload counter This is used for generating overflow condition and to customize the API usage AutoReloadVal Input Parameter 12 Bit value for auto reload register Output Parameters None Required Preconditions None Functions called None Postconditions Auto reload register is loaded with AutoReloadVal See also LART_ConfigurePWM 182 235 ky Function Descriptions Table 130 LART_LonglCAPMode Function Name Function Prototype LART_LongiCAPMode Void LART_LonglCAPMode Lart_LongICAPInitParams InitParams Behaviour Description Input Parameter Enables the long input capture function of LART This function selects the clock source as Lite Timer output In put capture source as Lite Timer input capture and inter rupt source as specified in InitParams InitParams LART SELF ICAP IT ENABLE Enables LART Input Capture interrupt LART LT ICAP IT ENABLE Enables Lite Timer Input Capture interrupt LART ICAP NO IT ENABLE No Input Capture interrupt is enabled Postconditions Output Parameters None Reguired Preconditions None Functions called None Clock source for LART is selected as Lite Timer output and Lite Timer Input capture is used as input capture source LART_LonglCAPGetValue is used to read values when input capture event occurs See also Notes LART_LonglCAPGetValue This function is available only for the ST7FLite3 device
23. all registers are also cleared except the Stop bit and address registers So to reinitiate the communication the 12C peripheral needs to be initial ized again 3 116 235 Function Descriptions Table 76 12Cs_ITFunction Function Name 12Cs_ITFunction Function Prototype Void I2Cs ITFunction void Transmits or receives data in Interrupt mode You must call this function inside the interrupt service routine Behaviour Description Input Parameters Output Parameters The I2C should be configured properly through I2Cs Init function Functions called None Postconditions See also Required Preconditions Note You must use this function only inside the Interrupt service routine Caution Special care must be taken when you write code with this function inside the interrupt service routine You are advised to call only this function inside Interrupt service routine Oth er wise data transfer synchronisation will be affected which may lead to data loss or errors EXAMPLE The following C program shows the uses of the I2C functions Program Description This program runs the following sequence for the 12C slave ST72F63B device for I2C Polling and I2C Interrupt driven communication modes 1 Transmits a single byte passed by the user and receives single byte of data in 7 bit ad dressing mode 2 Transmits and receives the10 bytes of data in 7 bit addressing mode The following modes are used fo
24. case I2Cs TX AF case I2Cs BERR case I2Cs GENERAL CALL case I2Cs ADDRESS DETECTED case I2Cs DEFAULT STATUS User Function break default User Function break endif RRRKKRKKKEKERKKEEND OF INTERRUPT DRIVEN MODE RRKKKKKREKKKKKKEKKEKE RRR RKRRKKKE RR K K K KERR KEK KEK KK ERK ERK KR KERR KERR KER KEK RK RR KA KKK RRRKKRK RECEIVER ROUTINE kkkkkkkkkkkkkkkkkk Error Status I2Cs IsReceptionCompleted while Time_Out amp amp Error Status I2Cs ADDRESS DETECTED amp amp Error Status I2Cs GENERAL CALL Error Status I2Cs IsReceptionCompleted 120 235 Y Function Descriptions Comm_Mode 12Cs_GetCommMode while Comm_Mode I2Cs DEFAULT Comm_Mode 12Cs_GetCommMode if Comm_Mode 12Cs_RX_MOD POLLING AND INTERRUPT DRIVEN RECEIVER Error Status I2Cs IsReceptionCompleted ONE BYTE RECEPTION while Time_Out amp amp Error Status I2Cs RX DATA OK Error Status I2Cs IsReceptionCompleted switch Error Status case I2Cs RX DATA OK first byte I2Cs GetByte break case I2Cs STOP DETECTED case I2Cs BERR case I2Cs GENERAL CALL case I2Cs ADDRESS DETECTED case I2Cs EMPTY case I2Cs DEFAULT STATUS User Function break default User Function break RRR KRKRKKKKKKEKKEKKEKEKEBUEPE ER RECEPTION A RRRKKKKKKKKKRKKEKPOLLING MODE ERRE KKK KKK K
25. unsigned char IO_PIN_6 unsigned char IO PIN 7 IO Output IO PUSH PULL IO PORT D unsigned char IO PIN 0 unsigned char IO PIN 1 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 IO_Output IO_OPEN_DRAIN IO_PORT_C unsigned char IO_PIN_0 unsigned char IO PIN 1 unsigned char IO PIN 2 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO PIN 6 unsigned char IO PIN 7 IO Output IO PUSH PULL IO PORT F unsigned char IO PIN 0 unsigned char IO PIN 1 unsigned char IO_PIN_2 unsigned char IO PIN 3 unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 IO Output IO OPEN DRAIN IO PORT E unsigned char IO_PIN_0 unsigned char IO_PIN_1 unsigned char IO_PIN_2 unsigned char IO_PIN_3 unsigned char IO_PIN_4 unsigned char IO PIN 7 IO ByteWrite IO PORT A unsigned char 0x77 IO ByteWrite IO PORT B unsigned char 0x88 IO ByteWrite IO PORT C unsigned char 0xAA IO ByteWrite IO PORT D unsigned char 0x55 IO ByteWrite IO PORT E unsigned char 0xFF IO ByteWrite IO PORT F unsigned char 0x1C 226 235 unsigned char IO PIN 6 Y Function Descriptions 9 2 APPLICATION SPECIFIC PERIPHERALS 9 2 1 CAN LIBRARY FUNCTION LIST Thi
26. 32 64 or 128 PR 1 COUNTER INPUT PR 2 fCOUNTER INPUT 2 PR 4 COUNTER INPUT 4 PR 8 fCOUNTER finPUT 8 PR 16 fcounTER INPUT 16 PR 32 fCOUNTER finput 32 PR 64 fcouNTER finPuT 64 PR 128 fcounTER finput 128 where INPUT fePU by default and finput fexr for external clock option None Required Preconditions This function does not support floating clock such as 5 33MFz Functions called Postconditions See also None 1 You must enable the interrupt with instruction rim 2 Interrupts are generated at the time base you provide PWMART_Counter_Enable Notes Here are some time base ranges corresponding to the various counter clock frequen cies fcounter fcounter 8MHz gives a time base range of 125ns to 31 875us from 1 step to 255 steps ARR 254 to ARR 0 counter 4MHz gives a time base range of 250ns to 63 75us fcounter 2MHz gives a time base range of 500ns to 127 5us fcounter 1MHz gives a time base range of 1us to 255us fcounter 500kHz gives a time base range of 2us to 510us fcounter 250kHz gives a time base range of 4us to 1 02ms 162 235 3 Function Descriptions fcounter 125kHz gives a time base range of 8us to 2 04ms fcounter 62 5kHz gives a time base range of 16us to 4 08ms Table 110 PWMART_PWM_Mode Function Name Function Prototype PWMART_PWM_Mode Void PWMART_PWM_Mode Pwmart_Pwm SELECT_Pin Pwmart_Output POLARITY
27. Byte Polling and Interrupt both and Interrupt mode Buffer I2C communication Input Parameters None Common I2Cs TX AF If Acknowledge failure condition is detected Also the SCL and SDA lines are released inside the function I2Cs BERR If misplaced start or stop condition detected I2Cs ADDRESS DETECTED If Address matched condition is detected 12Cs_GENERAL_CALL If the general call is detected I2Cs DEFAULT STATUS No communication event has occurred Byte Specific 12Cs_TX_DATA_OK Transmission of current byte has taken place successfully 12Cs_STOP_DETECTED If the stop condition is detected Output Parameters Buffer Specific 12Cs_BUFF_TX_ONGOING If the transmission of the buffer is ongoing successfully 12Cs_TX_DATA_OK Transmission has taken place successfully and Stop con dition is detected I2Cs OVERFLOW TX Transmission has taken place successfully and stop is de tected correctly But overflow condition has occurred Check through I2Cs_GetCommMode If I2Cs TX MODE is selected or not Required Preconditions Functions called None Postconditions None See also I2Cs IsReceptionCompleted Notes The above function is for both polling and Interrupt driven mode ButinI2C POLLING TX mode this function is used in conjunction with I2Cs PutByte only 112 235 S A Function Descriptions SCL and SDA lines are released in this function in case of Acknowledge failure and commu nication proceeds
28. CPOL 1 CPHA 1 59 235 Function Descriptions Input Parameter 2 You can select master slave in hardware software mode by selecting one of the below parameters SPI_MSTR_SW Selects Master in software mode SPI_SLAVE_SW Selects Slave in software mode SPI_HW Selects hardware mode You have to manage the SS pin accordingly for selecting Master Slave Output Parameters Required Preconditions Functions called None 1 SS pin must be GND for default slave mode 2 In hardware mode if slave has to transmit the SS pin of the slave has to be released and made HIGH before writing in SPIDR and reput to GND to avoid write collision error 3 Fcpu must be defined in ST7lib_config h 4 SPI port pin must be configured correctly in hardware SPI_Clear_Flags Postconditions See also If you want to enable the interrupt the SPI ENABLE IT pa rameter has to be passed in the SPI Init function After the SPI Init function is called you should use the macro Ena blelnterrupts macro to reset the Interrupt mask SPI Output Disable Note If you want to select the Interrupt driven communication mode you must enable inter rupts during initialization Table 29 SPI Output Disable Function Name SPI Output Disable Function Prototype Behaviour Description Void SPI Output Disable void Disables the alternate function of the SPI output Input Parameters Output Parameters None None
29. Enables the TLI capability on the dedicated pin Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Notes This function is for ST72F521 ST72F561 and ST72325 devices This is a Non Maskable Interrupt source and can interrupt a Level3 program Table 155 ITC_DisableTLI Function Name ITC DisableTLI Function Prototype Behaviour Description Void ITC DisableTLI void Disables the TLI capability on the dedicated pin Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Notes This function is for ST72F521 ST72F561 and ST72325 devices A parasitic interrupt can be generated when disabling the TLI depending upon the status of the TLI pin 204 235 3 Function Descriptions Table 156 ITC_TLISensitivity Function Name ITC TLISensitivity Function Prototype Void ITC TLISensitivity ITC Sensitivity Edge Behaviour Description rie eset IT_EDGE_R Pipir Paramst t TLI pin is made rising edge sensitive IT EDGE F TLI pin is made falling edge sensitive Output Parameters None Required Preconditions ITC DisableTLI must have been called Functions called None Postconditions None See also None Note This function is for ST72F521 ST72F561 and ST72325 devices EXAMPLE
30. I2C IT Function must have been called in the Interrupt service routine Functions called None Postconditions None See also None Notes The above function is for I2C Polling or I2C Interrupt driven mode It is recommended to use a timeout protection when using this function To terminate communication after receiving one byte using I2C GetByte you have to man age ACK bit and STOP generation as shown in the introduction 92 235 Y Function Descriptions Table 55 12C_GetBuffer Function Name Function Prototype I2C GetBuffer I2C RxErrCode tI2C GetBuffer unsigned char PtrTo Buffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Reguired Preconditions Receives number of data bytes and stores it in user de fined area for I2C Polling mode The data reception will stop if any error occurs during reception The reception status will be returned PtrToBuffer Start address of the user buffer NbOfBytes Number of bytes to be received I2C RX AF If Acknowledge failure has occurred I2C RX ARLO If Arbitration lost is detected I2C RX BERR If misplaced start or stop condition detected I2C DATA RX OK If there is no error in reception 1 12C Load Address must have been called If 12C is configured in the master receiver mode 2 You must define I2C Polling mode in ST7lib config h Functions called
31. ICF1 ICF2 OCF1 OCF2 or OVF F ICF1 Clears the Input Capture1 Flag F ICF2 Clears the Input Capture2 Flag F OCF1 Clears the output compare1 Flag F OCF2 Clears the output compare2 Flag F OVF Clears the timer overflow Flag None Required Preconditions Functions called ICF1 1 or ICF2 1 or OVF 1 or OCF1 1 or OCF2 1 None Postconditions See also Selected status flag is cleared TIMERx IT Routine TIMERx Status Flag 1 Function not available in ST72F65 134 235 3 Function Descriptions EXAMPLE The following C program shows the use of the TIMERx functions Here x A as TIMERA is used You must define TIMERA in ST7lib_contfig h Program description It compares the output compare2 register value with the free running counter checks the oc currence of event leading edge at ICAP2 pin It generates PWM signal with a frequency of 10KHz and a Duty cycle of 33 on the OCMP1 pin if Enable PWM is defined in ST7lib_confi h or it generates a 5ms pulse at OCMP1 pin if _Enable_OPM_ is defined in ST7lib_config h Fcpu 8 MHz Program start include st7lib_config h prototype declaration void main void void TIMERA_IT_Routine void void main void unsigned int OCR_VALUE 0x2050 IO Input IO FLOATING IO PORT F unsigned char IO_PIN_5 unsigned char IO PIN 6 ICAP1 ICAP2 pins asloating input TIMERA Ini
32. Integrated Circuit Bus Interface serves as an interface be tween the microcontroller and the serial 12C bus 12C Slave 16 bit Timer The timer consists of a 16 bit free running counter driven by a programmable prescaler 8 bit Timer The timer consists of a 8 bit free running counter driven by a programmable prescaler 8 bit Lite timer The Lite Timer can be used for general purpose timing functions PWM ART 8 bit The Pulse Width Modulated Auto Reload Timer on chip peripheral consists of an 8 bit auto reload counter with compare capture capabilities and of a 7 bit prescaler clock source AR 12 bit timer The 12 bit Autoreload Timer can be used for general purpose timing func tions TBU The Timebase unit TBU can be used to generate periodic interrupts WDG The Watchdog timer is used to detect the occurrence of a software fault ITC The Interrupt Controller manages the hardware and software interrupts with flexible in terrupt priority and level configuration MCC The Main Clock Controller consists of a programmable CPU clock prescaler a clock out signal to supply external devices and a real time clock timer with interrupt capability EEPROM The Electrically Erasable Programmable Read Only Memory can be used as a non volatile backup for storing data Os An I O port contains up to 8 pins Each pin can be programmed independently as digital input with or without interrupt ge
33. LOW Port A0 made low Y 149 235 Function Descriptions 9 1 8 LITE TIMER LT This software library consists of the following functions for LT Function Name LT Init Function Prototype Behaviour Description Void LT Init Lt InitParameter InitValue Initialization of the LT by default sets Timebase as 1ms watchdog and interrupts disabled lt initializes the input capture flag To change this default configuration you can pass one or more input parameters by logically ORing them together Input Parameter LT ICAP IT ENABLE enables input capture interrupt LT TB IT ENABLE enables Timebase interrupt LT TB1 IT ENABLE enables Timebase1 interrupt LT_TB2_IT_ENABLE 2 enables Timebase2 interrupt LT_DEFAULT sets default configuration Output Parameters None Required Preconditions None Functions called None Postconditions LT is configured as desired See also LT_TB 1 Present in ST7FLITEO and ST7SUPERLITE 2 Present in ST7FLITE1 2 3 and ST7FDALI Note By default this function also sets the timebase to 1ms To change the timebase to 2ms you can use the LT_TB function Table 97 LT_WDG_Enable Function Name LT_WDG_Enable Function Prototype Behaviour Description Void LT_WDG_Enable void Enables the watchdog Input Parameter None Output Parameters None Required Preconditions None Functions called None Postconditions See also Watchdog is e
34. None Required Preconditions None Functions called None Postconditions None See also None Notes The value of PtrToE2Buffer can be from 0x1000h to 0x107Fh for LITE0 1 2 3 ST7SUPERLITE and ST7DALI device You have to type cast parameter PtrToE2Buffer to unsigned char in the function EEPROM_Read as shown in example page 218 Because of the limitation of ST7FLite0 1 2 3 ST7SUPERLITE and ST7DALI ZRAM and RAM size which is 64 bytes each you must take care while declaring the size of user buffer 3 215 235 Function Descriptions Table 164 EEPROM_Write Function Name Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 Input Parameter 3 Output Parameters EEPROM_Write For Metrowerks void EEPROM Write unsigned char PtrToUsrBuffer unsigned char NbOfBytes unsigned char far PtrToE2Buffer For Cosmic void EEPROM Write unsigned char PtrToUsrBuffer unsigned char NbOfBytes near unsigned char PtrToE2Buffer Writes up to 32 bytes of data from user buffer to EEPROM memory PtrToUsrBuffer User address where data exists NbOfBytes Number of bytes you want to write in EEPROM memory You can write up to 32 bytes PtrToE2Buffer EEPROM memory address where data will be written None Required Preconditions Functions called None None Postconditions See also You must call EEPROM_ Programming after this function EEPROM_P
35. Port C as ei0 or ei1 The target ST7 device file st72xxx_periph h has to be included in this file Note An error message No Valid ST7 MCU Configuration will be generated by the compiler if no device file has been included 4 2 2 Non User part of the ST7lib config h This part contains the labels for METROWERKS and COSMIC compilers It contains the com piler definitions as follows if defined __HIWARE__ defined __MWERKS__ define _HIWARE_ else ifdef __CSMC__ define _COSMIC_ else error Unsupported Compiler Compiler defines not found endif endif The labels _ MWERKS__ __HIWARE__ and __CSMC__ are automatically set by the Metrowerks and cosmic compilers respectively If none of these two compilers are selected then an error message Unsupported Compiler appears on the debugger window Macros definitions in ST7lib_config h ST7lib_Config h file also contains a list of macros They are as follows 1 Enablelnterrupts You can use this macro to reset the interrupt mask this macro is equiva lent to the RIM instruction in assembly 2 Nop No operation This is equivalent to the nop instruction in assembly 3 Disablelnterrupts You can use this macro to set the interrupt mask this macro is equivalent to the SIM instruction in assembly 4 Waitforlnterrupt This is equivalent to the wfi instruction in assembly 4 3 PERIPHERALS LIBRARY 4 3 1 Peripherals directory Location ST7_
36. Postconditions None 12C_IsReceptionCompleted must be called after this func tion to get the status of reception See also Notes 12C_GetBuffer I2C Polling mode The above function is only for I2C Interrupt driven mode ACK bit is managed automatically inside this routine STOP bit is set automatically inside this routine before the last byte is read So there is no need to calll2C Generate Stop after this Caution Take care not to access the string until reception completion Any data received before calling this function is ignored The data reception will stop if any error occurs during reception In String reception the NULL character must be taken into account 94 235 3 Function Descriptions Table 57 12C_IsReceptionCompleted Function Name Function Prototype 12C_IsReceptionCompleted 12C_RxErrCode_t 12C_IsReceptionCompleted void Behaviour Description Input Parameters For reception of a set of data in I2C Interrupt driven mode the function checks for the completion of the recep tion or the occurrence of the error and returns the recep tion status For reception of single byte of data in both I2C Polling and 12C Interrupt driven modes it checks if a data byte is re ceived and ready for processing It returns I2C RX DATA EMPTY until the data byte is received and returns the reception status when reception is com plete None Outpu
37. ST72F63B devices only Notes This function replaces ITC EXT ITSensitivity from Library ver1 0 External Interrupts are masked when an I O configured as input interrupt of the same inter rupt vector is forced to Vss If several input pins of a group connected to same interrupt line are selected simultaneously these will be logically ORed Caution You must refer to the datasheet of the device while selecting the interrupt Pin and the Inter rupt sensitivity at that pin If you select a sensitivity which is not available for that pin the sen sitivity of the pin will not be changed 202 235 TA Function Descriptions For devices which have pins with fixed sensitivity the option IT DEFAULT has to be used Any other option used also has no effect and the default value is only configured For ST72F264 PortC can be configured as ElO or El1 using option bytes For this the con stant EXTIT VALUE in the device_hr h file has to be changed as 0 or 1 to configure PortC as ElO or El1 respectively Table 152 ITC_Disablelnterrupt Function Name ITC_Disablelnterrupt Function Prototype Behaviour Description VoidITC Disablelnterrupt ITC Port Portx unsigned char Pin Disables the interrupts at the specified Port amp Pin Input Parameter 1 IT Portx x A B C Input Parameter 2 Pin This value must be between 0 to 7 Required Preconditions Functions called The Port Pin must be c
38. ST7FLITEO9 ST7FLITE10 ST7FLITE15 ST7FLITE19 ST7FLITE1B ST7FLITE2 ST7FLITE20 ST7FLITE25 ST7FLITE29 ST72F260G1 ST72F262G1 ST72F262G2 ST72F264G1 ST72F264G2 ST72F561 ST72F561 R J K 9 ST72F561 R J K 6 ST7SUPERLITE ST7FLITES2 ST7FLITES5 ST72F264 4 5 DOCUMENTATION Location ST7_LIBx Documentation Description This directory contains the global user manual describing each peripheral library and its use in detail Files user manual pdf 4 6 DEMO Location ST7_LIBXDEMO Description This directory contains an application program which demonstrates the use of the ST7LIB on the devices ST72F521 ST72F62 ST7FLITEO ST7FLITE2 ST7SUPERLITE ST72F561 and ST72325 The program uses all the peripheral libraries together for a particular application The purpose of the demo is to help to develop an application using the software li brary 3 13 235 Example 5 EXAMPLE Location ST7_LIBx Peripherals Periph sources C Example Description Contains the example application code for each peripheral individually The code has been developed using the peripheral library functions exercises the functionality of that peripheral The configuration and workspace has been provided for users of both STVD7 ver2 x and 3 x The example has been compiled and tested using both Metrowerks and Cosmic compilers and configuration files are provided Subdirectories Sources workspace Sources Figure 2 Example di
39. TX_MSGx_DLC The length for the MSGx to be transmitted where x transmit message number The maximum length that can be defined is 8 7 RX_MSGx_DLC The length for the MSGx to be received where x receive message number The maximum length that can be defined is 8 8 REG INITx VALUE The register initialization value for the CAN controller register where REG register name x init structure number The following are the parameters that must be configured in the file user c 1 MSGx Tx Buffer This declares the buffer for the MSGx to be transmitted The length of the buffer is the same as defined by the parameter TX MSGx DLC in the file user h The number of such buffers to be declared is the same as defined by the parameter NO OF TX HANDLES in the file user h 2 tx_stdid This table stores the standard id value s for the message s to be transmitted The length of the table is the same as defined by the parameter NO OF TX HANDLES and the value s stored inside is are the same as defined by the parameter TX MSGx STDID in the file user h If the message to be transmitted is Extended then above has to logical ORed with the EXT ID MASK IDE bit EXID17 8 EXID16 bit values As a result the values stored inside the table are in the same format as of MIDRO amp MIDR1 registers 3 tx extid This table stores the extended id value s for the message s to be transmitted The length of the table is the same as defined by the paramete
40. The following C program shows the use of the ITC library functions Program description This program is written for the ST72F521 device It sets the Software priority level for EIO Ex ternal interrupt amp TIMERA peripheral interrupt to Level2 Then it sets the software priority of El2 to Level1 The sensitivity of PAO EIO interrupt pin in ST72F521 and PFO El2 interrupt is set to falling edge The TLI interrupt is enabled and the sensitivity of the TLI pin is set to Falling edge A falling edge is applied on the PFO pin configured as input interrupt to generate an El2 interrupt Immediately after this a falling edge is applied on the PAO pin As the priority of the ElO interrupt is higher than El2 the El2 interrupt is interrupted and control goes to ElO Then TLI interrupt is generated by applying a falling edge on the TLI pin The LEDs connected to the Port D pins are toggled by the interrupt subroutines Example code for ITC for ST72F521 include ST71ib_config h prototype declarations void TLI IT Routine void void EIO_IT_ Routine void void EI2_IT Routine void void main void void main void unsigned char Pin 0 ITC_LEVEL Priority IT_LEVEL_2 Variable Declaration ITC_Init Initialise ITC TTA 205 235 Function Descriptions EnableInterrupts Reset Interrupt mask ITC_SetPriority unsigned char IT_TIMERA unsigned char IT_EIO IT_LEVEL_2 Sets Interr
41. To be sure that the communication by this point has been completed if User Timeout Function else switch Temp2 case SPI RX MODF SPI RX OVR case SPI RX MODF case SPI RX OVR User Function Error Management break case SPI RECEIVE OK Reception successful break default If none of the above condition is met User Function break while 1 Time Out elapsed without reception completion Error in communication and user should handle the case ROUTINE NAME SPI User IT Routine INPUT OUTPUT None None DESCRIPTION Control comes into this routine when an interrupt is generated User can use the SPI interrupt service routine function or he can write his own code inside this routine at his own risk The data transfer syncronisation may be affected if user includes his own code along with SPI ISR function COMMENTS None ea o Z E n eee ea m nan n n m k l ae ae d fn m a m j fe fa So E a n ifdef _HIWARE_ Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved telse ifdef _COSMIC_ Test for Cosmic Compiler interrupt Cosmic interrupt handling else error Unsupported Compiler Compiler Defines not found endif ky 79 235 Function Descriptions endif void SPI User IT Routine void SPI IT Function BOOL User Timeout Function void while Timeoutco
42. Transmission mode SPI ITDRV WITHOUTBUF RX For Reception mode User can use a time out function to handle the fault in which the control will get stuck in side a loop This function should have the Boolean return i e it should return TRUE if the expected wait Time is not elapsed and FALSE if it is elapsed Software Control Wait loop User defined time out function k The following variables are declared in main h file main h ifndef MAIN define MAIN BOOL User_Timeout_Function void Prototypes of user function void User_Function void void SPI_User_IT_Routine void newly added Declaration of all global variables used inmain c define buf_size 0x0A define My_Data unsigned char 0x55 static unsigned int Timeoutcount endif 74 235 x Function Descriptions Program Start include ST71ib_config h List of all ST7 devices and communication mode include main h Declaration of prototypes of user defined functions used in main c void main void void main void unsigned char NbOfBytes_get 10 unsigned char NbOfBytes_put 10 unsigned char Rx_Data unsigned char Buff_Test buf_size unsigned char Buff buf size 0x00 0x55 0xAA 0xFF 0x00 0x55 0xAA 0xFF 0x00 0x55 SPI_TxErrCode_t Temp1 0x00 SPI_RxErrCode_t Temp2 0x00 SPI_Init unsigned char SPI DEFAULT unsigned char SPI_ENABLE unsigned ch
43. Tree the function Re entrant error occurs in case COSMIC compiler is used with models other than stack models The timer_hr h is included as the actual hardware register are read to clear the flags For configuring the port pins library is used Hifdef USE TIMERA ifdef HIWARE I O Test for HIWARE Compiler ROC SAVE_REGS Additional registers will be saved Test for Cosmic Compiler Compiler Defines not found Define local variables Clear ICF2 Call to clear ICF2 Ed Turn ON LED at PBO Delay Turn ON LED at PCO pragma TRAP P telse ifdef _COSMIC_ interrupt else terror Unsupported Compiler endif endif void TIMERA_IT_Routine void unsigned int CAP2_Value unsigned char i Temp if TACSR amp 0x10 if TIMERA_Status_Flag TIMER_FLAG_ICF1 TRUE Call to Check ICF2 Temp TACSR Temp TAIC2LR TIMERA_Clear_Flag TIMER_FLAG_ICF2 call to get capture value and also clear ICF2 CAP2 Value TIMERA ICAP Getvalue TIMER ICAP 2 Port PBO pushpull output IO Output IO PUSH PULL IO PORT B IO PIN 0 IO Write IO PORT B IO PIN 0 IO DATA HIGH turn on LED when input capture occurs for 1 0 i lt 250 1 Nop IO Write IO_PORT_B IO_PIN_0 IO_DATA_LOW endif 136 235 3 Function Descriptions 9 1 7 8 bit TIMER TIMER8 The software library for the 8 bit Timer
44. called Interrupts enabled or counter clock selected None Postconditions See also Overflow interrupt or compare interrupt or counter clock is OFF depending upon the input parameter passed LART_Init 1 Feature available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI devices 2 Feature available only on ST7FLite3 device Notes If PWM output is disabled the Output compare mode is enabled as the OE bit is cleared 172 235 3 Function Descriptions Table 117 LART_PWM_Mode Function Name Function Prototype LART_PWM_Mode Void LART_PWM_Mode unsigned int Autoreload_Value Lart_Output POLARITY unsigned int Dutycycle Data Behaviour Description Input Parameter 1 Input Parameter 2 Generates PWM on PWMO pin The PWM signal freguen cy is controlled by the counter clock period and ATR reg ister value The PWM signal duty cycle depends upon input parameter 1 and input parameter 3 This function is used only for LiteO device for other devic es use LART ConfigurePWM Autoreload Value This value is loaded in autoreload register ATR You can select this value from 0x000 to OxFFF depending on the freguency reguired for the PWM signal LART POLARITY 0 PWM output level is low for Counter value gt Dutycycle Data PWM output level is high for Counter value lt Dutycycle Data LART POLARITY 1 PWM output level is high for Counter value gt Dutycycle Data PWM output
45. e A A eon PE MEN AS io a ee Communication mode defined as POLLING TX in ST7lib config h ifdef I2C POLLING TX I2C Load Address Addr Byte Tx I2C TX MODE Templ 12C_IsTransmitCompleted while User Timeout Function amp amp Templ I2C ADD TX OK Templ 12C_IsTransmitCompleted switch Templ To check transmission status case I2C_TX_AF User_Function break default break 100 235 ISA Function Descriptions 3 Single byte data transmission I2C PutByte My Data Timeoutcount 0 Templ 12C_IsTransmitCompleted while User_Timeout_Function amp amp Temp1 12C_DATA_TX_OK Temp1 12C_IsTransmitCompleted switch Templ To check transmission status case I2C TX AF case I2C TX ARLO case I2C TX BERR User Function Error Management break default None of the above condition is true User Function break Transmission of 10 data bytes from user buffer switch I2C PutBuffer Buff unsigned char 10 case I2C TX AF case I2C TX ARLO case I2C TX BERR User Function Error Management break case I2C DATA TX OK break default None of the above condition is true User Function break I2C_Generate_Stop Transmission Stopped while I2C IsStopGen endif s sssslsss AA Communication mode defined as PO
46. gt 4 bit 1 953 500 KHz Table 111 PYMART ICAP Mode Function Name PWMART ICAP Mode Void PWMART ICAP Mode Pwmart Icap ICAP I Pwmart Sens IT Param SENS IT Value Selects the user defined transition on ARTICXx pin This function can be called twice to make use of both ARTICx pins You can pass one or more parameters from input pa rameter 2 by Bitwise ORing them together PWMART_ICAP_1 Input Capture at ARTIC1 pin is enabled PWMART ICAP 2 Input Capture at ARTIC2 pin is enabled PWMART SENSITIVITY F Falling edge triggers the capture PWMART SENSITIVITY R Rising edge triggers the capture PWMART ICAP1 IT ENABLE Enable input capture1 interrupt PWMART ICAP2 IT ENABLE Enable input capture2 interrupt Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters None 1 Function PYMART Counter Enable must have been Required Preconditions se 2 The input capture pins used must be configured as float ing inputs Functions called None 1 PWMART configured for input capture mode 2 To detect the occurrence of valid edge you can poll the Postconditions input capture flag using the function PWMART Status Flag In this case you should not ena ble the input capture interrupt PWMART Status Flag PWMART ICAP Getvalue See also 3 164 235 Function Descriptions Table 112 PWMART_ICAP_Getvalue Function Name Function Prototype PWMART_ICA
47. h 3 61 235 Function Descriptions Table 31 SPI_PutString Function Name SPI PutString SPI TxErrCode t SPI PutString const unsigned char PtrToString Transmits data string from the user defined address for SPI Polling mode The data transmission will stop if any error occurs during transmission The transmission status will be returned PtrToString Start address of the user string SPI TX WCOL If write collision error occurs SPI_TX_MODF If master mode fault occurs SPI_TRANSMIT_OK If there is no error in transmission 1 SPI should be configured correctly 2 You must define SPI Polling mode in ST7lib config h Function Prototype Behaviour Description Input Parameters Output Parameters Required Preconditions Functions called Postconditions See also SPI PutString SPI Interrupt driven mode Notes The above function is only for SPI Polling mode For transmission in software slave mode you must define SPI SLAVE CONFIG in ST7lib_config h Caution The application can lose control if the SPI is disabled while using this function in poll ing mode 3 62 235 Function Descriptions Table 32 SPI PutBuffer Function Name SPI_PutBuffer SPI_TxErrCode_t SPI_PutBuffer const unsigned char PtrToBuffer unsigned char NbOfBytes Transmits data bytes from the user defined area for SPI Polling mode The data transmission will stop if any error occu
48. is disabled MCC CLK 2 Selects clock as foscz 2 MCC CLK 4 Selects clock as foscz 4 MCC CLK 8 Selects clock as foscz 8 MCC CLK 16 Selects clock as fosco 16 MCC_CLK_32 Selects clock as foso 32 None Required Preconditions Functions called MCC Init must have been called None Postconditions See also None None 1 This parameter is applicable for ST72F521 ST72325 and ST7232A devices when slow mode is enabled 2 This parameter is applicable for ST7FLiteO device when slow mode is enabled 3 209 235 Function Descriptions Table 158 MCC RTC Timer Function Name MCC RTC Timer Function Prototype VoidMCC RTC Timer MCC RTC Param Timer Value Selects the programmable divider time base Oscillator in terrupts are generated as per the timebase selection You have to select the input values from the table shown be low MCC RTC X x 0 1 2 3 You have to select values to decide the time base for os cillator interrupt Behaviour Description Input Parameters Output Parameters None Required Preconditions MCC Init must have been called Functions called None Postconditions None See also None Notes The MCC RTC interrupt wakes up the MCU from ACTIVE HALT mode not from HALT mode A modification of time base is taken into account at the end of the current period previously set to avoid an unwanted time shift Ti
49. mode is enabled the po larity of the PWM Output waveform may change 3 142 235 Function Descriptions Table 92 TIMER8_OPM_Mode Function Name Function Prototype TIMER8_OPM_Mode Void TIMER8_OPM_Mode Timer8_Edge EDGE_SELECT_Y Timer8_Olevel OUTPUT1_L Timer8_Olevel OUTPUT2_L unsigned char OCR_VALUE Behaviour Description Configures the timer8 in One Pulse Mode It enables the generation of pulse when an external event occurs If PWM and OPM modes are both active then OPM will not work In OPM mode OCMP1 cannot be used for output compare only OCMP2 is available for output compare Input Parameter 1 Input Parameter 2 Input Parameter 3 Input Parameter 4 Output Parameter TIMER8_EDGE_X X 0 input capture1 occurs at falling edge X 1 input capture1 occurs at rising edge TIMER8_OUTPUT1_F Low level is reflected at the output compare pin after suc cessful comparison of output compare register with free running counter TIMER8_OUTPUT1_R High level is reflected at the output compare pin after successful comparison of output compare1 register with free running counter TIMER8_OUTPUT2_F Low level is reflected at the output compare pin after suc cessfully capturing edge at ICAP1 pin TIMER8_OUTPUT2_R High level is reflected at the output compare pin after successfully capturing edge at ICAP1 pin OCR VALUE You can select this value from 0x00 to OxFC None Requir
50. of data bit SCI PO LOW PH HIGH Default value on CLK pin low CLK activated at the beginning of data bit SCI PO HIGH PH LOW Default value on CLK pin High CLK activated in the middle of data bit SCI PO HIGH PH HIGH Default value on CLK pin high CLK activated at the beginning of data bit SCI LBCL DISABLE The CLK pulse of last data bit is not output to the pin SCI LBCL ENABLE The CLK pulse of last data bit is output to the pin None Reguired Preconditions Functions called None None Postconditions See also SCI clock is availaible at a dedicated pin during communi cation None 52 235 3 Function Descriptions EXAMPLE The following C program shows how the SCI functions are used This program runs the following sequence for an SCI without extended baudrate prescaler for polling or interrupt driven mode transmits a single byte passed by the user transmits the 20 bytes of data at the baudrate 9600 receives 20 bytes of data at a baud rate of 9600 Note You must define the communication mode and cpu speed Fcpu in the ST7lib_config h file You can select any of the communication speeds from the following list SCI_POLLING_TX For Transmission mode SCI_POLLING_RX For Reception mode SCI ITDRV WITHOUTBUF TX For Transmission SCI ITDRV WITHOUTBUF RX For Reception You can use a timeout function to handle the fault in which the control will get stuck i
51. or the occurrence of an error and returns the reception status In both Polling and Interrupt driven modes the function checks if a single byte of data is received and ready for processing It returns SCI RX DATA EMPTY until the data byte is received and returns the reception status af terwards Input Parameter None SCI BUFFER ONGOING User buffer is not full SCI STRING ONGOING Complete string is not received in the user buffer SCI NOISE ERR Noise error occurred during reception SCI OVERRUN ERR Overrun error occurred during reception SCI FRAMING ERR Framing error occurred during reception SCI RECEIVE OK Error free data is stored in the user buffer SCI PARITY ERR Parity error occurred during reception SCI RX DATA EMPTY No data byte is received Reguired Preconditions None Functions called None For single byte reception if the byte is received then SCIx_GetByte can be called after this function Behaviour Description Output Parameters Postconditions 1 These Parameters are returned in Interrupt driven mode only 2 This Parameter is returned in case of single byte reception only for both Polling and Inter rupt driven modes Notes If this function is called before any reception request is made it will check for single byte re ception and will return SCI RX DATA EMPTY until the data byte is received and returns the reception status afterwards 3 49 235 Function
52. supports the following function Note Currently Timer8 is only available for ST72F561 Function Name Function Prototype TIMER8 Init Void TIMER8 Init Typ Timer8 InitParameter InitValue Behaviour Description Initializes the timer8 control registers and status register to their default values Timer8 clock can be selected as Fcpu 2 Fcpu 8 and Fcpu 8000 Default value of clock is Fcpu 4 Input Parameters TIMER8_FCPU_2 Timer clock is set to Fcpu 2 TIMER8_FCPU_4 Timer clock is set to Fcpu 4 TIMER8_FCPU_8 Timer clock is set to Fcpu 8 TIMER8_FCPU_8000 Timer clock is set to Fcpu 8000 TIMER8_DEFAULT Reset value Default value 3 Output Parameters None Reguired Preconditions None Functions called None Postconditions Timer8 clock is configured correctly See also None 137 235 Function Descriptions Table 87 TIMER8_IT_Enable Function Name TIMER8_IT_Enable Void TIMER8_IT_Enable Typ_Timer8_ElTParameter ElTVal ue Function Prototype Enables the timer8 interrupts One or more input parameters can be passed by logically ORing them together TIMER8_OCMP_IT_ENABLE Enables the output compare interrupts TIMER8_ICAP_IT_ENABLE Enables the input capture interrupts TIMER8_OVF_IT_ENABLE Enables the timer overflow interrupt Behaviour Description Input Parameters Output Parameters Required Preconditions Functions called None Interrupt is enabled for a particular
53. the application Application must call CanInterruptDisable and CanInterruptRestore services when clearing the indication flag in order to avoid CAN interrupt Overflow flag is set by the driver if the indication flag is not cleared by the application or mes sage is not copied by the application from the global buffer into the application buffer If the overflow is set it means that the new message has been overwritten over the previous message Overflow flag has to be cleared by the application Application must call Caninter ruptDisable and CaninterruptRestore services when clearing the overflow flag in order to avoid CAN interrupt While copying data from receive buffer application must call CanInterruptDisable and CaninterruptRestore services in order to avoid a CAN interrupt Similarly while copying ky 25 235 How to use the library data into the transmit buffer application must call CanlnterruptDisable and CanlnterruptRestore services to avoid an interrupt 6 3 OTHER PERIPHERALS 6 3 1 TIMER TIMERA and TIMERB can both be used simultaneously depending on the TIMER selected You have to define USE_TIMERA and or USE_TIMERB in ST7lib_config h Each function name in the user manual contains TIMERx where x can be A or B depending on whether it is for TIMERA or TIMERB This is also explained in the example given at the end of the TIMER library 6 3 2 I O You must select the following parameters a
54. to select the required device unsigned char TIMER8_OCR_VALUE 0x50 Configuring the Port B pin 0 amp 2 as floating for ICAP1 and ICAP2 IO Input IO FLOATING IO PORT B unsigned char IO PIN 0 unsigned char IO_PIN_2 e endif n n endif while 1 TIMER8_Init TIMER8_1 EnableInterrupts E ali s TIMER8_Clear_Flag TIMER8_F e E i Run TIMI ifdef Enable OPM IMER8 Clear Flag TIMER8 FLAG ICF1 TIMER8 Mode Disable TIMER8 MODE 5 0 1ms pulse TIMER8 Status Flag TIMER8 PWM Mode TIMI TIMER8 OPM Mode TIM FCPU 8 MP 2 TIMER8 OC TIMER8 FLAG O LAG OCF2 ER8 IT Enable TIMER8 ICAP IT ENABLE tect rising edge at ICAP2 pin R8 ICAP Mode TIMER8 ICAP 2 TIMER8 ED ER8 EDGE 1 TIM Timer8 Clock to Fcpu 8 and reset counter Clear I bit in CC reg ES Timer8 compares 0x50 with free running counter R8_OCMP_Mode TIMER8 OC R VALUE TIMER8 OU CF2 TRUE s TPUT R Clear output compare2 flag Enable capture interrupt GE 1 Run TIMER8 in PWM mode if Enable PWM is defined ifdef Enable PWM Ef Generate PWM of frequency of 10 KHz ER8 in OPM mode if _Enable_OPM_is defined ER8_OUTPUT1_F TIM ER8_OUTPUT1_F TIMER8_OUTPUT2_R 0x1C 0x5F ah Clear Input capturel Flag Disable PWM ye Program end 148 235 ER8_OUTPUT2_R 0x5F
55. unsigned char Dutycycle_Data Behaviour Description Selection of PWM pin polarity and duty cycle You have to call this function more than once to generate several PWM signals Input Parameter 1 PWMART Pin Pin 0 PWM signal on PWMO port pin Pin 1 PWM signal on PWM1 port pin Pin 2 PWM signal on PWM2 port pin Pin 3 PWM signal on PWM3 port pin Input Parameter 2 Input Parameter 3 PWMART POLARITY 0 PWM output level is low for Counter value gt Dutycycle Data PWM output level is high for Counter value lt Dutycycle Data PWMART POLARITY 1 PWM output level is high for Counter value gt Dutycycle Data PWM output level is low for Counter value lt Dutycycle Data Dutycycle Data Data to be loaded in corresponding OCR register 0x00 to OxFFh Note This value must be greater than the ARR register value loaded through PWMART Enable function Refer to the table given below Output Parameters Required Preconditions None PWMART_Counter_Enable must have beeb called Functions called Postconditions None PWM signal is generated on the selected pin See also None Note The table given below shows data to be loaded in ARR register for different PWM signal 3 163 235 Function Descriptions frequency and resolution 0x00 to OxFFh ARR value Resolution fpwm 0 0 244 31 25 KHz 0 127 0 244 62 5 KHz 128 191 0 488 125 KHz 192 223 0 977 250 KHz 224 239
56. zil Transmitter routine with or without buffer Stop Condition Receiver routine with or without buffer Stop Condition Note This is a general flow part Error management is not shown here for the purpose of sim plicity TTA 107 235 Function Descriptions Table 64 I2C Slave Functions Function Name Function Prototype I2Cs Init Void I2Cs Init I2Cs Control Param InitParam unsigned char I2Cs OAR1Value unsigned char I2Cs OAR2Value Behaviour Description By default Acknowledge and General Call are disabled You can change the default configuration by selecting in put parameters given below You can pass one or more parameters by logically ORing them I2C peripheral is also enabled Input Parameter 1 Input Parameter 2 Input Parameter 3 Output Parameters I2Cs DEFAULT PARAM Load I2C control registers with default value I2Cs ENABLE ACK Enables acknowledge I2Cs ENABLE ENGC Enables General Call I2Cs OAR1Value Load the OAR1 address I2Cs OAR2Value Load 10 bit higher address bits and also sets FRi bits ac cording to the value of Fcpu None Required Preconditions O port should be configured correctly Functions called None Postconditions None See also None Notes For ST72F63B device there is only one address register I2COAR It does not support 10 bit addressing Here I2COAR will get the value of I2Cs OAR
57. 1Value and the value of I2Cs OAR2Value will be neglected If single master 12C device is selected 12C will remain idle as in this case I2C can not behave as slave When slave is in the interrupt mode That is if ifdef I2C_ITDRV_WITHOUTBUF_TX Or ifdef 12C_ITDRV_WITHOUTBUF_RX are defined then ITE bit is also set in control register automatically There is no separate parameter for enabling the ITE bit Caution If ITE bit is forcibly modified in the User routine using the hardware register then the behav iour of the I2C slave library is unpredictable If you are using the 12C as both transmitter and receiver then both should be configured in the same mode Polling Interrupt driven 108 235 ky Function Descriptions Table 65 12Cs_GetCommMode Function Name Function Prototype 12Cs_GetCommMode 12Cs_Mode I2Cs GetCommMode void Behaviour Description Input Parameters It will return I2Cs DEFAULT mode before first BTF event and will return I2Cs TX MODE orIl2Cs RX MODE mode after that None Output Parameters I2Cs TX MODE Slave is transmitter I2Cs RX MODE Slave is receiver I2Cs DEFAULT The default mode Required Preconditions I2Cs IsReceptionCompleted Functions called None Postconditions None See also None Notes 1 Inl2Cs DEFAULT mode you should use I2Cs_IsReceptionCompleted to detect the start condition As by default the slave is considered as a
58. 218 OALINAZLS 60S LNAZLS goaLN4Zis c0SLNAZls YZEJZZLS GZEACLLS eMVEACLIS c pOWP O SZEASLL Ss lt 6 94 P D 8W SZE42 418 LEGaZZ1S S9ACZLS 1g 1 9v3833218S veesdeLls abeescZ1 L3E43L1S S S g LZS4ZZL beSAeZL goszzis 5 gegscZls EMAE9ICZ1S ZMAL942 1S 5 1Mg 93341S 2943 L1S Aje qd LL9AZZLS EZ94ZL1S lt 23943218 1294341S SN d pouoddns ADC scl SPI 12C Master amp Slave Timer 16 bit timer Timer8 8 bit Timer LT 8 bit LiteTimer PWMART LART 12 bit ART TBU WDG ITC MCC EEPROM vo CAN Note 1 This software library supports only beCAN basic extended 2 0b active CAN cell which is found for example in the ST72F561 devices The ST72F521 device has a pCAN peripheral 2 0b passive CAN cell and therefore is not supported 233 235 Revision History 11 REVISION HISTORY Date Revision Main changes Support given for ST72325 and ST7232A devices 27 Oct 05 4 0 Section 3 2 on page 8 new hardware tools added Support given for WDG in LITE3 devices 234 235 3 Revision History THE PRESENT MANUAL WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH INFORMA TION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME AS A RESULT STMICROELEC TRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT INDIRECT OR CONS
59. 8 fCOUNTER finputis PR 16 fcounter finput 16 PR 32 fcounter finput 32 PR 64 fcounter INPUT 64 PR 128 fcounter finput 128 where INPUT fePU by default and finput fexr for external clock option Output Parameters None Required Preconditions PWMART Init must have been called Functions called None Postconditions Counter starts running See also PWMART_Init Notes To use PWMART as a timebase use the following procedure Depending upon the time base required you have to calculate the value of Counter Data to be loaded in ARR register This value can be calculated from the following equation Counter_Data Timebase Tcounter where Timebase time base required by user and Tcounter 1 fcounter OR You can use PWMART_OCMP_Timebase function 160 235 3 Function Descriptions Table 108 PYMART OCMP Mode Function Name Function Prototype PWMART OCMP Mode Void PWMART OCMP Mode Pwmart Compare OC MP Pwmart Output POLARITY unsigned char Compare Data Behaviour Description Input Parameter 1 Configures the timer in Output compare mode You have to call this function more than once to enable several out put compares PWMART OCMP O where O can be O 1 2 Or 3 O 0 Output Compare register 0 value is compared with counter value O 1 Output Compare register 1 value is compared with counter value O 2 Output Compare register 2 value is compared wi
60. AP interrupt Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Note This is a Non Maskable Software Interrupt and can interrupt a Level3 program 3 201 235 Function Descriptions Table 151 ITC_Configurelnterrupt Function Name ITC_Configurelnterrupt VoidITC Configurelnterrupt ITC Port Portx unsigned char Pin ITC Sensitivity Sensitivity Enables the interrupts and also Sets the Interrupt sensitiv ity of the selected Port pin Function Prototype Behaviour Description IT Portx Input Parameter 1 x A B C D E F Pin Input Parameter 2 This value must be between 0 to 7 IT EDGE F 0 Sets the interrupt sensitivity of the selected pin as falling edge and Low level IT EDGE R Sets the interrupt sensitivity of the selected pin as rising edge only IT EDGE F Sets the interrupt sensitivity of the selected pin as falling Input Parameter 3 edge only IT EDGE FR Sets the interrupt sensitivity of the selected pin as falling edge and rising edge IT EDGE R 1 Sets the interrupt sensitivity of the selected pin as rising edge and high level IT DEFAULT Sets the default sensitivity associated with the device Reguired Preconditions The Port Pin must be configured in Input Interrupt mode Functions called None Postconditions None See also ITC Disablelnterrupt 1 This option to be used for ST72F62 and
61. DE Behaviour Description Input Parameters Disables the PWMART mode depending upon Input pa rameter passed This function should be called more than once in order to disable more than one functionality PWMART_PWMO_DISABLE Disable PWMO output PWMART PWM1 DISABLE Disable PWM1 output PWMART PWM2 DISABLE Disable PWM2 output PWMART PWM3 DISABLE Disable PWM3 output PWMART OVF IT DISABLE Disable OVF interrupt PWMART ICAP1 IT DISABLE Disable ICAP1 interrupt PWMART ICAP2 IT DISABLE Disable ICAP2 interrupt PWMART COUNTER DISABLE Disable PWMART counter Output Parameters None Required Preconditions PWMART active in any mode Functions called None Postconditions See also Selected PWMART functionality is disabled None 168 235 3 Function Descriptions EXAMPLE The following C program shows the use of the PWMART functions Program description This program detects the event rising edge at ARTIC1 pin and generates the PWM signal of frequency 50KHz with duty cycle 33 on the PWM1 pin for ST72F521 device with a 4MHz ex ternal clock The output compare signal is obtained on the PWM2 pin Program start include ST7lib_config h Select ST72F521 prototype declaration void PWMART_IT_Routine void void main void void main void unsigned char Counter Data 0xBO unsigned char Compare_Data 0xCA unsigned char DutyCycle_Data 0xCA ARTIC1 ARTIC2 ARTCLK as floating input
62. Description The ST7 libx where x represents the latest numeric version of the library is in stalled by default in the root directory It is comprised of five main components the ST7library configuration file the Peripherals Device driver library folder the devices configuration files folder documentation on the package and the demo folder The location of these components is described in this section and shown in the figure given below Note The Example directory is shown in Figure 2 on page 14 Figure 1 Main Directory structure ST7 UBx ST7lib_config h Peripherals Devices Documentation Demo Periph 1 Device 1 Periph 2 Device n Periph14 device_reg h device_reg c C Folder device_periph h Metrowerks Example Cosmic periph c periph h periph hr h 4 2 ST7LIB_CONFIG H Location ST7_libxST7lib_config h Description ST7lib config h is the entry point for the user You have to include this file in your application main c This file is used to define specific labels for example to define the mode of transmission of communication peripherals cpu frequency etc 10 235 S72 Library Structure St7lib_config h is divided into two major sections 4 2 1 User part of the ST7lib_config h You can customize this portion to your application reguirement You can define your own labels and macros here You can change the CPU clock value default is 8MHz For the ST72F264 device you can select whether to use
63. Descriptions If a reception request for a set of data is over this function will return the error status of that request only once If this function is called again before making next reception request then the function will check for single byte reception In Polling mode this function is used in conjunction with SCIx GetByte only Table 25 SCIx Forced Clear Flag Function Name Function Prototype SCIx Forced Clear Flag Void SCIx Forced Clear Flag void Behaviour Description Input Parameters Clears all the status and Error flags TC TDRE RDRF IDLE OR NF FE PE in SCI Status register SCISR None Output Parameters Required Preconditions None Transmission or Reception must have taken place Functions called Postconditions None None See also None Note You can call this function whenever you want to force the error and status flags be cleared Caution Do not call this function if a reception request is ongoing as it will corrupt the recep tion status by clearing all the flags and you will not receive any error status Table 26 SCIx IT Function Function Name Function Prototype SCIx IT Function Void SCIx IT Function void Behaviour Description Input Parameters Transmits or receives data in Interrupt driven mode You must call this function inside the interrupt service routine None Output Parameters Reguired Preconditions No
64. E ERK KER KA K KKK KEE KE Time_Out Function KKK KK K K K K RARE RE K RARE K K K K K K K RRR KK REE K K K A K K K KA RARA RR K K KKK KKK A RRA A RR RAR RARA ARS BOOL Time Out void while count lt 5000 count return FALSE Time out not elapsed return TRUE Time out elapsed void User_Function void I2Cs ErrorClear user can include his code here 123 235 3 Function Descriptions 9 1 6 16 bit TIMER TIMER This software library for the 16 bit TIMER can be used for both Timer A and Timer B To use any of the timers you have to replace x by A or B Function Name TIMERx_Init Function Prototype Void TIMERx_Init Typ_Timer_InitParameter InitValue Initializes the timer control registers and status register to their default values Timer clock can be selected as Fcpu 2 Fcpu 8 and external clock can also be set Default value of clock is Fcpu 4 TIMER_FCPU_2 Timer clock is set to Fcpu 2 TIMER_FCPU_4 Timer clock is set to Fcpu 4 TIMER_FCPU_8 Timer clock is set to Fcpu 8 TIMER_EXCLK_F Timer counter will be triggered through the falling trailing edge of external clock TIMER_EXCLK_R Timer counter will be triggered through the rising leading edge of external clock TIMER_DEFAULT Reset value Default value Behaviour Description Input Parameters Output Parameters None Required Preconditions None Functions called None Postconditions Timer cloc
65. EFAULT PARAM2 Sets standard speed mode I2C FASTSPEED Sets fast speed mode I2C Speed You can select any value from 0 to 400 Standard speed mode range 0 to 100 kHz Fast speed mode range 101 to 400 kHz None Reguired Preconditions 1 12C_Init must have been called 2 Fcpu must be defined in ST7lib_config h 3 For multimaster 12C configuration the I2C MultiMaster Config function must have been called 4 If you enter speed ranges from 101 to 400 kHz the pa rameter I2C FASTSPEED must be selected in input pa rameter 1 Functions called None Postconditions None See also None Note I2C speed is strongly dependant on the R and C wired on the lines Fepu and V y values and not solely on the value programmed in I2CCCR register So you must take account of the R and C values You must not pass the speed value less than the minimum speed limit For ex minimum speed limit for F py 8MHz is 16 kHz 3 83 235 Function Descriptions Table 46 12C_Generate_Start Function Name Function Prototype I2C Generate Start Voidl2C Generate Start void Behaviour Description Input Parameters Generates start condition None Output Parameters Reguired Preconditions Functions called None 1 12C Select Speed must have been called 2 In 12C Interrupt driven mode I2C IT Function must have been called in the Interrupt service routine None Postconditions See also 12C_
66. EQUENTIAL DAMAGES WITH RE SPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH A MANUAL AND OR THE USE MADE BY CUS TOMERS OF THE INFORMATION CONTAINED HEREIN IN CONNEXION WITH THEIR PRODUCTS Information furnished is believed to be accurate and reliable However STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics Specifications mentioned in this publication are subject to change without notice This publication supersedes and replaces all information previously supplied STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners O 2005 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 3 235 235
67. Function Descriptions Table 85 TIMERx_Mode_Disable Function Name Function Prototype TIMERx_Mode_Disable Void TIMERx_Mode_Disable Timer_Mode MODE_M Behaviour Description Input Parameter Disables the timer mode depending upon Input parameter passed This function should be called more than once to disable more than one mode TIMER_MODE_M where M can be 1 2 3 4 5 6 7 8 9 M 1 Output compare1 mode OCMP1 M 2 Output compare 2 mode OCMP2 M 3 Input capture 1 mode ICAP1 M 4 Input capture 2 mode ICAP2 M 5 Pulse width modulation mode PWM 1 M 6 One pulse modulation mode OPM 1 M 7 Forced compare1 mode FORCDCMP1 M 8 Forced compare2 mode FORCDCMP2 M 9 timer prescalar counter and outputs disabled Output Parameters Reguired Preconditions None Timer active in any of the modes Functions called Postconditions None Selected timer mode is disabled and the Corresponding status flag is cleared See also 1 Function not available in ST72F65 3 None 133 235 Function Descriptions Table 86 TIMERx_Clear_Flag Function Name Function Prototype TIMERx_Clear_Flag Void TIMERx Clear Flag Timer Flag FLAG F Behaviour Description Input Parameters Output Parameters Clears the status flag depending upon the input parameter passed This function can be called more than once to clear more than one flag TIMER FLAG F where F can be
68. IO Input IO Input Mode Input Val IO Port Port Val1 IO Pin Pin Val1 Configures the I O ports in input mode You can also se lect external interrupt function by selecting the corre sponding input parameters Refer to the datasheet to select the input mode and input port name Select the input mode by selecting one of the below pa rameters IO FLOATING Selects floating input mode IO FLOATING IT Selects floating input mode with external interrupt IO PULL UP Selects pull up input mode IO PULL UP IT Selects pull up input mode with external interrupt Selects the port name Input Parameter 2 IO PORT X X A B The port name has to selected with reference to the datasheet Selects port pin number You can select more than one pin Function Prototype Behaviour Description Input Parameter 1 Input Parameter 3 number by OR ing them IO PIN Y Y 0to 7 Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Notes You can use this function to configure pins as floating input when the pins are used as ADC input If you want to select external interrupt you should use the Enablelnterrupts macro after this function Caution Alternate function must not be activated while the pin is configured as input with interrupt in order to avoid generating spurious interrupts Input pull up configuration ca
69. IO PORT E unsigned char IO_PIN_0 unsigned char IO_PIN_1 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO PIN 6 unsigned char IO_PIN_7 IO_DATA_HIGH IO Write IO_PORT_F unsigned char IO_PIN_0 unsigned char IO_PIN_1 while Temp 0x3f while Temp 0xf8 while Temp 0xe7 while Temp 0xe3 unsigned char IO PIN 2 unsigned char IO_PIN_3 unsigned char IO PIN 6 unsignedchar IO PIN 7 IO DATA HIGH IO Write IO PORT B unsigned char IO PIN 0 unsigned char IO PIN 1 unsigned char IO PIN 2 unsigned char IO PIN 3 unsigned char IO PIN 6 unsignedchar IO PIN 7 IO DATA LOW R1 Reads the port D con RT_ Reads the port D con RT_ Reads the port D con R17 Reads the port D con RT Reads the port D con RT Reads the port D con while Temp 0xcf Temp IO while Temp Temp 0x00 Temp IO Temp 0x00 Temp IO Temp 0x00 Temp IO Temp 0x00 Temp IO Temp 0x00 Temp IO IO Input IO PULL UP IO PORT A unsigned char IO PIN 2 unsigned char IO PIN 3 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 IO Input IO FLOATING IO PORT C unsigned char IO_PIN_2 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO_PIN_5 tents
70. IsTransmitCompleted should be called after this to ensure that start condition is generated correctly None Notes A start condition is not generated unless I2C Initorl2C Generate Stop is called before this function When start condition is generated for ST72F65 ST72F521 ST72F63B ST72325 devices the I2C switches over from Idle Slave modes to Master mode Y 84 235 Function Descriptions Table 47 12C_Load_Address Function Name Function Prototype I2C Load Address Voidl2C Load Address unsigned char Addr Byte I2C Mode Param Mode Value Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters In master mode transmits the address byte to select the slave device Addr Byte You can select any value from 00 to FFh You have to pass one of the below parameters I2C TX MODE Enters into transmitter mode after slave address is trans mitted I2C RX MODE Enters into receiver mode after slave address is transmit ted I2C SUB ADD You must pass this parameter if slave sub address has to be transmitted None Reguired Preconditions 1 12C Generate Start must have been called 2 In 12C Interrupt driven mode I2C IT Function must have been called in the Interrupt service routine Functions called Postconditions None If you want to transmit the sub address the slave address where the transmitted data to be received in case of trans m
71. KA KKK RE KK KKK KK KR Y ifdef I2C POLLING RX Error Status I2Cs GetBuffer Buff In maxsize switch Error Status case I2Cs RX DATA OK case I2Cs OVERFLOW RX break case I2Cs BERR case I2Cs ADDRESS DETECTED case I2Cs GENERAL CALL User Function break default User Function break endif RRRKRKKKE end of polling mode RRKKKKKE KERR KERR KKK KER RE KR K K RRR KKRKK K K KTNTERRUPT DRIVEN MODE KKKKKKKAZ KKK KKK ERE RKKKKEKKEREKE EE S72 121 235 Function Descriptions Hifdef I2C ITDRV WITHOUTBUF RX Error Status I2Cs IsReceptionCompleted while Time Out amp amp Error Status I2Cs RX DATA OK Error Status I2Cs IsReceptionCompleted switch Error Status case I2Cs BUFF RX ONGOING case I2Cs OVERFLOW RX case I2Cs BERR case I2Cs EMPTY case I2Cs ADDRESS DETECTED case I2Cs GENERAL CALL User Function break case I2Cs RX DATA OK break default User Function break I2Cs GetBuffer Buff In maxsize Error Status I2Cs IsReceptionCompleted while Time Out amp amp Error Status I2Cs RX DATA OK Error Status I2Cs IsReceptionCompleted switch Error Status case I2Cs BUFF RX ONGOING case I2Cs OVERFLOW RX case I2Cs BERR case I2Cs EMPTY case I2Cs ADDRESS DETECTED case I2Cs GENERAL CALL User Function break case I2Cs RX DATA OK break default User Function break endif
72. LLING RX in ST7lib config h Single byte data reception ifdef I2C POLLING RX I2C Generate Start while 12C_IsTransmitCompleted I2C START OK I2C Load Address Addr Byte Tx I2C RX MODE Timeoutcount 0 Templ 12C_IsTransmitCompleted while User Timeout Function amp amp Templ I2C ADD TX OK Templ 12C_IsTransmitCompleted i switch Templ To check reception status case I2C_TX_AF User_Function 101 235 Function Descriptions 102 235 break default break Timeoutcount 0 Temp2 12C_IsReceptionCompleted while User_Timeout_Function amp amp Temp2 I2C RX DATA EMPTY Temp2 12C_IsReceptionCompleted Waits for data byte reception if User_Timeout_Function switch Temp2 case I2C RX ARLO case I2C RX BERR Rx Data I2C GetByte Corrupted data byte received User Function Error Management break case I2C DATA RX OK Reception successful Rx Data I2C GetByte break default None of the above condition is true User Function break Handle time out as Transmitter Receiver is having some problem Reception of a set of data switch I2C GetBuffer Buff Test unsigned char 10 case I2C_RX_ARLO case I2C RX BERR User Function Error Management break case I2C DATA RX OK break default None of the above condition is met User Function
73. MP 1 is configured LART OCMP2 OCMP2 is configured LART OCMP3 OCMP3 is configured Input Parameter 2 Dutycycle Data Data to be loaded in Duty cycle register 0x000 to OxFFF which will be compared with upcounter Output Parameters Reguired Preconditions None LART_Init must have been called to select the counter clock Functions called Postconditions See also None When the upcounter value reaches the Dutycycle Data the CMPFxflag is set and an interrupt is generated if com pare interrupt is enabled LART_Init LART OCMP Mode 1 Feature available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI devices Note Take care of the ATR value while using this function 176 235 Y Function Descriptions Table 121 LART_Status_Flag Function Name LART_Status_Flag Function Prototype BOOL LART Status Flag Lart Flag FLAG F Checks the status of any one of the LART flags depending Behaviour Description upon the input parameter passed The function can be called more than once for checking more than one flag FLAG F LART FLAG OVF Checks Overflow flag LART_FLAG_CMPFO Checks Output Compare 0 flag LART_FLAG_CMPF1 Checks Output Compare 1 flag Input Parameters LART_FLAG_CMPF2 Checks Output Compare 2 flag LART FLAG CMPF3 Checks Output Compare 3 flag LART FLAG ICF Checks Input Capture flag LART FLAG OVF2 Checks counter 2 overflow flag TRUE or FALSE Outpu
74. None Required Preconditions Functions called 1 Input Capture pin used must be configured as floating input or pull up without interrupt 2 Only input capture2 can be used if PWM or OPM is ac tive None Postconditions 1 Timer8 configured for input capture mode 2 To detect the occurrence of valid edge you can poll the input capture flag using the function TIMER8_Status_Flag This is in case you have not ena bled the input capture interrupt See also TIMER8_Status_Flag TIMER8_PWM_Mode TIMER8_OPM_Mode TIMER8_ICAP_Getvalue 3 140 235 Function Descriptions Table 91 TIMER8_PWM_Mode Function Name Function Prototype TIMER8_PWM_Mode Void TIMER8_PWM_Mode Timer8_Olevel OUTPUT1_L Timer8_Olevel OUTPUT2_L unsigned char OCR1_VALUE unsigned char OCR2_VALUE Behaviour Description Configures the timer8 in Pulse width modulation mode It enables the generation of a signal with frequency and duty cycle depending upon the input parameters you have giv en If PWM and OPM modes are both active then only PWM works In PWM mode the ICAP1 pin cannot be used for input capture function but ICAP2 can be used Input Parameter 1 Input Parameter 2 Input Parameter 3 Input Parameter 4 Output Parameters TIMER8_OUTPUT1_F Low level is reflected at the output compare pin after suc cessful comparison of output compare register with free running counter TIMER8_OUTPUT1_R Hig
75. O define LT_WDG prototype declaration voidLT ICAP IT Routine void voidLT TB IT Routine void 156 235 Y Function Descriptions void main void volatile unsigned int count void main void PB3 and PB1 as pushpull output TO_Output IO_PUSH_PULL IO_PORT_B unsigned char IO_PIN_3 unsigned char IO_PIN_1 Set Time base to 1ms Input capture and Timebase interrupts enabled LT_TInit unsigned char LT ICAP IT ENABLE unsigned char LT_TB_IT_ENABLE Clear I bit in CC register EnableInterrupts Micro defined in the st7lib config h ifdef LT WDG Use of force watchdog reset LT_WDG_Enable LT WDG Reset LT FORCD WDG RESET endif LT WDG while 1 For Testing only Program end FERRE REA RARE REE K K K K AK KA K KK K K KA KK K K RRE K KA K KK K K KKK KKK K KA KKK K kk kkk kk RR KKK k k k k k k k Use of Input capture Interrupt service routine User has to write this function and map the interrupt vector in prm filein case of HIWARE or invector xxx c in case of COSMIC An example of LED toggles at port PB1 is given which will be executed when capture occurs This gets automatically executed if the ICAP interrupt of the LT is enabled If the same functions are called in the main Tree and the interrupt Tree the function Reentrant error occurs in case COSMIC compiler is used with models other than stack models Functions descript
76. O A SS AS V E Ss a SN Window Watchdog for setting a Refresh Period of 34ms and a Window Size of 18 432ms at fosc2 8MHz Reset is generated after 1ms by reloading the WDG counter register outside the window A EE ifdef WDG 72F561 WDG_Refresh 0x50 Set a Refresh period of 34ms WDG_WriteWindow 0x48 for i 0 i lt 532 i 1ms delay WDG_Refresh 0x50 Generates Reset on execution of this routine endif while 1 IS 195 235 Function Descriptions 9 1 13 ITC Table 146 ITC_Init Function Name ITC_Init Function Prototype Behaviour Description Void ITC_Init void Initializes all the Interrupt software priority registers and External interrupt controller status register to their default values Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Table 147 ITC_SetPriority Function Name ITC_SetPriority Function Prototype Behaviour Description Input Parameter 1 196 235 Void ITC_SetPriority ITC_IT IT ITC_LEVEL Level Sets the Interrupt software Priority levels of the selected interrupts IT_MCC Sets the software priority of MCC interrupt IT_EIO Sets the software priority of External interruptO IT El1 Sets the software priority of External interrupt1 IT El2 Sets the software priority of External interrupt2 IT_El3 Sets the software priority of Extern
77. OVF checks for overflow flag Output Parameters Reguired Preconditions TRUE or FALSE If TRUE flag is set If FALSE flag is not set PWMART must be configured in any one of the mode Functions called Postconditions None If the output parameter is TRUE flag is set and can be cleared by calling PYMART Clear Flag in case of ICF1 and ICF2 In case of OVF there is no need to call PWMART Clear Flag If the output parameter is FALSE the flag is not set and this function can be looped until the flag is set See also 166 235 None 3 Function Descriptions Table 114 PWMART_Clear_Flag Function Name Function Prototype PWMART Clear Flag Void PWMART Clear Flag Pwmart Flag FLAG F Behaviour Description Input Parameters Clears the status flag depending upon the input parameter passed This function can be called more than once to clear more than one flag PWMART FLAG F PWMART FLAG ICF1 clears the input capture1 f lag PWMART FLAG ICF2 clears the input capture 2 flag PWMART FLAG OVF clears the overflow flag Postconditions Output Parameters None Required Preconditions ICF1 1 or ICF2 1 or OVF 1 Functions called None Selected status flag is cleared See also 3 PWMART Status Flag 167 235 Function Descriptions Table 115 PYMART Mode Disable Function Name Function Prototype PWMART Mode Disable Void PWYMART Mode Disable Pwmart Dparam MO
78. PPENDIX A Siro EI Ai lo 233 10 1SUPPORTED DEVICES AND THEIR PERIPHERALS 233 11 REVISION HISTORY cccccccc a 234 6 235 3 Overview 2 OVERVIEW 2 1 FUNCTIONAL SCOPE ST7 library is a software package consisting of device drivers for all standard ST7 peripherals Each device driver has a set of functions covering the functionality of the peripheral The source code developed in C is fully documented and thoroughly tested This library has been developed to make it easy for you to develop ST7 applications A basic knowledge of C programming is required With ST7 library you can use any ST7 device in your application without having to study each peripheral specification in depth As a result using this library can save you a lot of coding time and save part of the cost of developing and integrating your application 2 2 FEATURES NEW Supports new devices ST72325 and ST7232A NEW Provided workspace for both STVD7 version 3 x and 2 x The ST7 library package consists of device driver library files the configuration and setup files With each peripheral application example code is provided This is an application tailored to a specific ST7 device which uses the library functions to drive the peripheral You can use it without modification in an ST development kit A detailed function reference is provided for each peripheral The functional behaviour and input output paramet
79. PWMART Returns the software priority of PWMART peripheral inter rupt IT DTC Returns the software priority of DTC interrupt IT PLG Returns the software priority of Power Management USB plug unplug interrupt IT ESUSP Input Parameter 1 Returns the software priority of USB Endsuspend interrupt IT USB Returns the software priority of USB peripheral interrupt IT TIM Returns the software priority of TIMER interrupt IT ADC Returns the software priority of A D End of Conversion in terrupt IT CSS Returns the software priority of Clock Filter interrupt IT SCI IT SCI2 Returns the software priority of SCI interrupts IT LEVEL 0 Priority of the selected interrupt is at LevelO IT LEVEL 1 Priority of the selected interrupt is at Level1 IT LEVEL 2 Priority of the selected interrupt is at Level2 IT LEVEL 3 Priority of the selected interrupt is at Level3 Reguired Preconditions None Functions called None Postconditions None See also None Output Parameter Notes This function is for ST72F521 ST72F561 ST72F65 ST72F62 ST72F264 ST72325 and ST7232A devices This function is for Nested Interrupts only Caution If you select an interrupt which is not present in the Peripheral then he will get an error message during compilation 200 235 TA Function Descriptions Table 150 ITC TRAP Function Name ITC TRAP Function Prototype Void ITC TRAP void Behaviour Description Generates TR
80. P_Getvalue Unsigned char PWMART_ICAP_Getvalue Pwmart_Icap ICAP I Behaviour Description Input Parameters Returns the input capture1 or input capture 2 register val ue depending upon the input parameter passed This function should be called twice in order to get both input capture1 and input capture2 register values PWMART ICAP I PWMART ICAP 1 Input capture 1 register value is returned PWMART ICAP 2 Input capture 2 register value is returned Output Parameters Input capture 1 or Input capture 2 register value The re turned value can be in the range of 0x00 to oxFF Reguired Preconditions ICF1 and or ICF2 1 You have to call this function after the ICF1 and or ICF2 flag is set to get the capture value Functions called Postconditions See also None 1 Input capture1 or Input capture 2 register value is re turned 2 Input capture flag is cleared PWMART ICAP Mode Y 165 235 Function Descriptions Table 113 PWMART_Status_Flag Function Name Function Prototype PWMART_Status_Flag BOOL PWMART_Status_Flag Pwmart_Flag FLAG_F Behaviour Description Input Parameters Checks the status of any one of the PWMART flags de pending upon the input parameter passed The function can be called more than once for checking more than one flag PWMART_FLAG_F PWMART FLAG ICF1 checks for input capture1 flag PWMART FLAG ICF2 checks for inpur capture 2 flag PWMART FLAG
81. Parameters are returned in SPI Interrupt driven mode only 2 This Parameter is returned in case of single byte reception only for both SPI Polling and SPI Interrupt driven modes Notes In SPI Polling mode this function is used in conjunction with SPI GetByte only If this function is called before any reception reguest is made it will check for single byte re ception and will return SPI RX DATA EMPTY until the first data byte is received and re turns the reception status when reception is complete If a reception request is over this function will return the error status of that request only once If this function is called again before making next reception request then the function will check for single byte reception 72 235 ky Function Descriptions Table 42 SPI_IT_Function Function Name SPI_IT_Function Function Prototype Void SPI_IT_Function void Transmits or receives data in SPI Interrupt driven mode You must call this function in the interrupt service routine Behaviour Description Input Parameters Output Parameters You must have called transmission or reception function in SPI Interrupt driven mode before this Functions called None Postconditions See also Required Preconditions Note You must use this function only in the Interrupt service routine Caution Special care must be taken while you write your own code along with this function inside the interr
82. R VALUE You can select this value from 0x0000 to OxFFFF None Reguired Preconditions Functions called 1 Timer correctly configured 2 Timer interrupt due to input capture 1 can be used by en abling the input capture interrupt None Postconditions 1 Timer is active in Pulse width modulation mode and waveform can be seen on OCMP1 pin 2 Output compare interrupt is inhibited See also 1 Function not available in ST72F65 Notes TIMERx_Init TIMERx_ICAP_Mode Flags for compare1 8 compare 2 can not be set by hardware in PWM mode therefore the output compare interrupt is inhibited 128 235 ky Function Descriptions The flag due to capture1 is set by hardware when counter reaches the output compare 2 register value and can produce the timer interrupt if the input capture interrupt is enabled and the instruction rim is used to clear the I bit in CC register By enabling the Forced compare mode or OPM mode while PWM mode is enabled the po larity of the PWM Output waveform may change 3 129 235 Function Descriptions Table 82 TIMERx_OPM_Mode Function Name Function Prototype TIMERx OPM Mode Void TIMERx OPM Mode Timer Edge EDGE SELECT Y Timer Olevel OUTPUT1 L Timer Olevel OUTPUT2 L unsigned int OCR VALUE Behaviour Description Configures the timer in One Pulse Mode It enables the generation of a pulse when an external event occurs I
83. REAK function None Postconditions All registers are initialized to Reset state So Init and other function required to configure the required LART function ality must be called again See also LART_ConfigureBREAK LART_ActivateBREAK Note This function is available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI de vices 3 181 235 Function Descriptions Table 128 LART Counter2lnit Function Name Function Prototype LART_Counter2Init Void LART_Counter2Init Lart_CTR2InitParams InitPar ams unsigned int ATR2Value Behaviour Description Input Parameter This function enables counter 2 which is used for PWM2 PWM3 and loads the autoreload register for counter 2 This also enables counter 2 overflow interrupt depending upon the input parameters passed InitParams LART CTR2 OVF IT ENABLE Enables counter 2 overflow interrupt LART CTR2 OVF IT DISABLE Disables counter 2 overflow interrupt ATR2Value Value to be loaded in Autoreload register 2 which is used for counter 2 Output Parameters None Reguired Preconditions None Functions called None Postconditions See also Counter 2 is configured for PWM2 and PWM3 LART Disable Note This function is available only for the ST7FLite3 device Table 129 LART ReloadATR Function Name Function Prototype LART ReloadATR Void LART_ReloadATR unsigned int AutoReloadVal Behaviour Description
84. RRE RAR KK RK k k k k k k RR Interrupt Subroutine for EIQ RRR RK KKK KR KEKE KKK KER K KA KKK K K KA K KKK KR KA K KK KK KR KKK KKK A RK KEK KKK KKK KK KERR ERK RRR RE REKEKKEE RE ifdef _HIWARE_ Test for HIWARE Compiler tpragma TRAP PROC SAVE REGS Additional registers will be saved else ifdef COSMIC Test for Cosmic Compiler interrupt Cosmic interrupt handling else terror Unsupported Compiler Compiler Defines not found 206 235 TTA Function Descriptions endif endif void EI0 IT Routine void unsigned int i PDDDR 0x01 PDOR 0x01 PDDR 0x01 for i 0 i lt 5000 i Nop PDDR amp OxFE FERRERA RARE RE K KA K K K AK K KA K K K A K EEK KER KKK KKK RK ERK KKK KK RK KK EKER RRE k k k k k k k k k k k k k k k k k k Interrupt Subroutine for EI2 KKKKA KKK KK KA KK A KK KERR KR KKK RR KEK KKK KER KK KKK KR KKK K KK A KKK K KKK KK KEKE KERR KA K K KKK RKKEKER ifdef _HIWARE_ Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved else ifdef _COSMIC_ Test for Cosmic Compiler interrupt Cosmic interrupt handling else error Unsupported Compiler Compiler Defines not found endif endif void EI2 IT Routine void unsigned int i PDDDR 0x02 PDOR 0x02 PDDR 0x02 for i 0 i lt 5000 i Nop PDDR amp OxFd 3 207 235 Function Des
85. Request The message is aborted if the mailbox is in pending or scheduled state The confirmation flag is not set for this message 3 228 235 Function Descriptions Table 175 CanMsgTransmit Function Name Function Prototype CanMsgTransmit canuint8 CanMsgTransmit tCanMsgObject lt tx Data gt Input Parameters Output Parameters Behaviour Description Reguired Preconditions txData Pointer to structure which contains CAN Id CAN DLC CAN Frame Data KCANTXOK Reguest is accepted by CAN driv er KCANTXFAILED Reguest is not accepted by CAN driver This service initiates the transmission for the message referenced by lt txData gt The service returns KCANTXOK if the CAN driver accepts the reguest The service returns KCANTXFAILED otherwise This service shall not be called when the CAN driver is in stop or sleep mode Table 176 CanCancelMsgTransmit Function Name Function Prototype CanCancelMsgTransmit void CanCancelMsgTransmit void Input Parameters Output Parameters None None Behaviour Description 3 This service cancels a transmit reguest from the service CanMsgTransmit 229 235 Function Descriptions 9 2 1 3 Sleep Wakeup Services Table 177 CanSleep Function Name CanSleep Function Prototype canuint8 CanSleep void Input Parameters None KCANFAILED If Sleep mode not entered KCANOK If Sleep mode entered Thi
86. SPI_POLLING_RX Single byte data reception Temp2 SPI_IsReceptionCompleted while User Timeout Function amp amp Temp2 SPI RX DATA EMPTY Waits for data byte reception Temp2 SPI_TsReceptionCompleted Waiting for data byte reception if User Timeout Function switch Temp2 case SPI RX MODF SPI RX OVR case SPI RX MODF case SPI RX OVR User Function Error Management Rx Data SPI GetByte Corrupted data byte received break case SPI RECEIVE OK Reception successful Rx Data SPI GetByte break default If none of the above condition is met User Function break else while 1 Handle time out as Transmitter Receiver is having some problem Reception of set of data switch SPI_GetBuffer Buff_Test unsigned char 10 case SPI_RX_MODF SPI_RX_OVR case SPI_RX_MODF case SPI_RX_OVR User Function Error Management break case SPI RECEIVE OK Reception is successful break 76 235 ky Function Descriptions 3 default If none of the above condition is met User Function break endif ooooooooooooooooooooooooooooooooooo o ooo o SSS SS o ifdef SPI ITDRV WITHOUTBUF TX Single byte transmission SPI PutByte My Data Here user can perform other tasks or operations except transmission till the time t
87. ST7 SOFTWARE LIBRARY USER MANUAL November 2005 977 A Ref DOC ST7SOFT LIB USE IN LIFE SUPPORT DEVICES OR SYSTEMS MUST BE EXPRESSLY AUTHORIZED STMicroelectronics PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS WRITTEN APPROVAL OF STMi croelectronics As used herein 1 Life support devices or systems are those which a are intended for surgical implant into the body or b support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided with the product can be reasonably expected to result in significant in jury to the user 2 A critical component is any component of a life support device or system whose failure to perform can reasonably be expected to cause the failure of the life support device or system or to affect its safety or effectiveness AY USER MANUAL ST7 FAMILY ST7 SOFTWARE LIBRARY 1 INTRODUCTION This document describes the features the files structure examples module drivers and guidelines for using the ST7 software library package 1 1 ABBREVIATIONS USED 1 2 NAMING CONVENTIONS e SCI e ADC e SPI e 12C e CAN e WDG EEPROM e ITC I O e PWM ART e TBU e TIMER TIMER8 e LT LART e STVD7 e MCD Serial Communication Interface Analog to Digital Converter Serial peripheral Interface Inter Integrated Circuit Controller Area Networ
88. TION sn see eee tee eae de Ab v o o k 13 4 6 DEMO nt aia sE dod oo n dd du Says 13 MEXAMPEE lt a ao yl o n ye See on A oh 14 5 1 SOURCES FOLDER o ddd ee de st ree ao tc eas 14 5 2 WORKSPACE 3 2503 too day eee ee a es 15 Sel B DA fiw abe eae sii 15 4 235 ky Table of Contents O22 IE A O RN 15 5 2 3 winIDEA only for ST72F561 and CAN peripheral 15 6 HOW TO USE THE LIBRARY oo A ee Se ee 16 6 1 STANDARD PROCEDURE FOR ALL PERIPHERALS 16 6 2 USING THE COMMUNICATION PERIPHERALS LIBRARY 17 62 1 SGI zs et Seeurthoeyeweteieirte apie bebe nea pr a eee eS 17 A O AN 18 623 A O O 19 6 2 4 GAN A O L la das 21 6 2 4 1 DESCRIPTION us dash 8 Gand La ii ate iia eee 22 6242 DATA STRUCTUBES coincida coer badly eh ball 22 5243 DATA TYPES usura aia 23 6 2 4 4 MEMORY USAGE zs ba o ot ea tie att in 23 6 2 4 5 PARAMETER CONFIGURATION 2 200005 23 6 2 4 6 Tx amp Ax BUFFER USAGE ios wee eee A po l 25 6 2 4 7 IMPLEMENTATION HINTS 0020 00 e eee eee 25 6 3 OTHER PERIPHERALS 22 ccs ee Yo Slee eee ee eee aes 26 6 3 1 TRIMER ir EEE area 26 A A V O seare Ba ce Rete A get 26 6 4 MEMORY MODELS 936g tetel cence a 26 6 5 PORTING APPLICATIONS FROM LIBRARY VERSION 1 0 26 7 PRESENTATION OF LIBRARY FUNCTIONS 0000 2c eee o 27 7 1 LIBRARY REFERENCES 229 ous nau os oh ead Pawar nee eee ees 27 8 RELEASE INFORMATION sec 2 e008
89. The C3 and C4 port pins are put into logic high state by the external input Then port C is read The read value is compared with expected value i e 0x18 If there is any mismatch between the data read and expected data the control goes into a while loop Program Start include ST71ib_config h void main void void main void 224 235 File for user to select device as ST72F521 unsigned char Temp 0x00 TO_Init IO Output IO PUSH PUL unsigned char All IO registers initialised to reset value 00h L IO PORT A unsigned char IO PIN 1 IO_PIN_2 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO PIN 5 unsigned char IO PIN 6 unsignedchar IO PIN 7 IO Output IO OPEN DRAIN IO PORT B unsigned char IO PIN 0 unsigned char IO_PIN_4 IO_Output IO_PUSH_PUL unsigned char IO_PIN_2 unsigned char IO_PIN_3 unsigned char unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsigned char IO_PIN_7 L IO PORT C unsigned char IO PIN 0 IO PIN 1 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO PIN 5 unsigned char IO PIN 6 IO Output IO OPEN DRA unsigned char unsig IO Output IO PUSH PUL unsigned char IO PIN 3 unsigned char IO_PIN_7 IN IO_PORT_D unsigned char IO_PIN_0 IO_PIN_1 unsigned char
90. WMART by default sets counter clock as Fcpu counter stopped and interrupt disabled You can select external clock One or more input parameters can be passed by logically ORing them together Input Parameter PWMART DEFAULT Reset value 00h PWMART EXCLK Enable the external clock source PWMART OVF IT ENABLE Enable counter overflow interrupt Postconditions Output Parameters None Reguired Preconditions None Functions called None PWMART is configured as desired See also Y PWMART_Counter_Enable 159 235 Function Descriptions Table 107 PWMART_Counter_Enable Function Name Function Prototype PWMART_Counter_Enable Void PWMART_Counter_Enable Pwmart_Counter SELECT REG unsigned char Counter Data Pwmart Clock SELECT CLK Behaviour Description Input Parameter 1 Initializes the PWM counter You can select counter fre quency PWMART_REG_C where C can be CAR or ARR If C ARR Counter is forced to be loaded with ARR reg ister at each overflow automatically and clears prescaler register If C CAR Counter is loaded with CAR register on the fly and clears prescaler register Input Parameter 2 Counter_Data Data to be loaded in ARR register or CAR register Data can be selected from 0x00 to OxFF Input Parameter 3 PWMART CLK PR where PR can be 1 2 4 8 16 32 64 or 128 PR 1 fcounter INPUT PR 2 fcounTER INPUT 2 PR 4 fcounter finput 4 PR
91. _HIWARE_ test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS additional registers will be saved else ifdef _COSMIC_ test for Cosmic Compiler interrupt else error Unsupported Compiler Compiler Defines not found endif endif void PWMART_IT_Routine void unsigned char CAP1_Value unsigned char i Temp if PWMART Status Flag PWMART FLAG OVF TRUE PWMART_Clear_Flag PWMART_FLAG_OVF call only to clear OVF if PWMART Status Flag PWMART_FLAG_ICF1 TRUE PWMART_Clear_Flag PWMART_FLAG_ICF1 call only to clear ICF1 call to get capture value and also clear ICF1 CAP1 Value PWMART ICAP Getvalue PWMART ICAP 1 Routine for user code IO Output IO PUSH PULL IO PORT C IO PIN 0 IO Write IO PORT C IO PIN 0 IO0 DATA HIGH Turn ON LED at PCO for i 0 i lt 250 i delay Nop IO Write IO_PORT_C IO_PIN_0 IO_DATA_ LOW Turn ON LED at PCO 170 235 kyr Function Descriptions 9 1 10 LITE AUTO RELOAD TIMER LART This software library consists of the following functions for LART Function Name LART_Init Function Prototype Behaviour Description Void LART_Init Lart_InitParameter InitValue Initialization of the LART by default counter clock is OFF and interrupts disabled To change this default configura tion you can pass one or more input parameters by logi cally ORing them together Input Parameter LART_COUNTER_CLK_FLT
92. a register is returned See also None Note The EOC flag may be set again during the execution of this function this depends on the conversion time 32 235 3 Function Descriptions Table 6 ADC_Disable Function Name ADC_Disable Function Prototype Void ADC_Disable void Behaviour Description Stops ADC conversion on the selected channel Input Parameters None Output Parameters None Required Preconditions ADC is switched on Functions called None Postconditions ADC switched off See also ADC_Enable Example The following C program shows the use of the ADC functions Program description This program converts the analog value on channel 5 of the ST72F62 device to a digital value Program start include st7lib config h Select st72F62 device ES void main void void main void unsigned int Conv_Datal Variable to get the converted digital value unsigned char channel 5 ADC Init unsigned char ADC_SPEED unsigned char ADC_ONESHOT FADC FCPU 4 ADC_Select_Channel channel Channel 5 selected ADC_Enable Start conversion while ADC Test Conversn Complete FALSE Conv_Datal ADC_Conversn_Read Read the converted value ADC_Disable Nop Macro defined in st7lib_config h Program end 3 33 235 Function Descriptions 9 1 2 SCI This Library supports 2 SCI of ST72F561 device
93. a transmission will stop if any error occurs during transmission The transmission status will be returned PtrToBuffer Start address of the user buffer NbOfBytes Number of data bytes to be transmitted 12C_TX_AF If Acknowledge failure has occurred I2C TX ARLO If Arbitration lost is detected I2C TX BERR If misplaced start or stop condition detected I2C DATA TX OK If sub address is successfully transmitted or there is no er ror in data transmission Reguired Preconditions 1 12C Load Address must have been called If 12C is configured in the master transmitter mode 2 You must define I2C Polling mode in ST7lib config h Functions called Postconditions None None See also I2C PutBuffer I2C Interrupt driven mode This is applicable only in multimaster 12C Note The above function is only for I2C Polling mode Caution The application can lose control if I2C is disabled when using this function in 12C Polling mode 88 235 3 Function Descriptions Table 51 12C_PutString Function Name Function Prototype 12C_PutString Void 12C_PutString const unsigned char PtrToString Behaviour Description Input Parameters Output Parameters Starts transmission of a data string in I2C interrupt driven mode from the user defined area PtrToString Start address of the user string None Required Preconditions 1 12C Load Address must have been called If 12C is
94. according to the 12C protocol This function should be called again to de tect the next event START STOP Table 70 12Cs GetBuffer Function Name I2Cs GetBuffer Function Prototype Behaviour Description I2Cs ErrCode t12Cs GetBuffer unsigned char PtrTo Buffer unsigned char MaxSize Receives data bytes inI2C POLLING RX mode and stores in the buffer whose start address is passed as pointer The data reception will discontinue if any error oc curs during reception and the error status will be returned Input Parameter 1 PtrToBuffer Start address of the user buffer Input Parameter 2 MaxSize Maximum size of the buffer Output Parameters Required Preconditions Functions called I2Cs BERR Bus error is detected I2Cs ADDRESS DETECTED If address matched condition is detected I2Cs GENERAL CALL lf general call is detected I2Cs RX DATA OK If there is no error in data transmission and stop condition is detected correctly I2Cs OVERFLOW RX lf reception has taken place correctly but overflow condi tion has occurred 1 You must define I2C POLLING RX mode in ST7lib config h 2 I2C communication must be detected through the 12Cs_GetCommMode None Postconditions See also Notes None I2Cs GetBuffer I2C Interrupt driven mode I2Cs PutBuffer The above function is only for I2C POLLING RX mode Control from this function comes only after receiving a STOP or any Err
95. acter The returned value can be in the range of 0x00 to OxF9 ICF 1 You have to call this function after the ICF flag is set to get the capture value None Postconditions 1 Input capture register value is returned 2 Input capture flag is cleared See also 154 235 None 3 Function Descriptions Table 105 LT_Status_Flag Function Name Function Prototype LT_Status_Flag BOOL LT Status Flag Lt Flag FLAG F Behaviour Description Input Parameters Output Parameters Checks the status of any one of the LT flags depending upon the input parameter passed The function can be called more than once for checking more than one flag LT FLAG TBF checks for Timebase interrupt flag LT FLAG TB1F checks for Timebase1 interrupt flag LT FLAG TB2F checks for Timebase2 interrupt flag LT FLAG ICF checks for input capture flag LT FLAG WDGRF checks for watchdog reset status flag TRUE or FALSE If TRUE flag is set If FALSE flag is not set Required Preconditions Functions called LT configured in any one of the modes None Postconditions If the output parameter is TRUE flag is set If the output parameter is FALSE the flag is not set and this function can be looped till the flag is set See also None 1 Defined for ST7FLITEO and ST7SUPERLITE 2 Defined for ST7FLITE1 2 3 and ST7FDALI Note After calling this function for a particular flag the cor
96. al interrupt3 IT_CAN Sets the software priority of CAN peripheral interrupt IT SPI Sets the software priority of SPI peripheral interrupt IT_TIMERA 2 Sets the software priority of TIMERA peripheral interrupt IT_TIMERB 2 Sets the software priority of TIMERB peripheral interrupt IT sci Sets the software priority of SCI peripheral interrupt Y Function Descriptions Input Parameter 1 Input Parameter 2 Output Parameter IT_AVD Sets the software priority of Auxiliary Voltage detector in terrupt IT I2C Sets the software priority of I2C peripheral interrupt IT PWMART Sets the software priority of PWMART peripheral interrupt IT DTC Sets the software priority of DTC peripheral interrupt IT PLG Sets the software priority of Power Management USB plug unplug interrupt IT ESUSP Sets the software priority of USB Endsuspend interrupt IT USB Sets the software priority of USB peripheral interrupt IT TIM Sets the software priority of TIMER interrupt IT ADC Sets the software priority of A D End of Conversion Inter rupt IT CSS Sets the software priority of Clock Filter Interrupt IT SCI IT SCI2 Sets the software priority of SCI interrupts IT LEVEL 1 Sets the priority of the selected interrupt as Level1 IT LEVEL 2 Sets the priority of the selected interrupt as Level2 IT LEVEL 3 Sets the priority of the selected interrupt as Level3 None Reguired Preconditions None Functions ca
97. all this function after the ICF1 and or ICF2 flag is set to get the capture value Functions called Postconditions None Input capture 1 or Input capture 2 register value is re turned See also 1 Function not available in ST72F65 TIMERX_ICAP_Mode Note The input capture flag gets cleared if this function is called after the TIMERx_Status_Flag 3 131 235 Function Descriptions Table 84 TIMERx_Status_Flag Function Name Function Prototype TIMERx_Status_Flag Bool TIMERx Status Flag Timer Flag FLAG F Behaviour Description Input Parameters Output Parameters Checks the status of any one of the timer flags depending upon the input parameter The function can be called more than once for checking more than one flag TIMER FLAG F where F can be OCF1 OCF2 ICF1 ICF2 or OVF F OCF1 checks for OCF1 flag F OCF2 checks for OCF2 flag F ICF1 checks for ICF1 flag F ICF2 checks for ICF2 flag F OVF check for OVF flag TRUE or FALSE If TRUE flag is set If FALSE flag is not set Reguired Preconditions Functions called Timer must be configured in any one of the modes None Postconditions If TRUE timer flag is set and can be cleared by calling TIMERX_Clear_Flag If FALSE timer flag is not set and this function can be looped till the flag is set See also 1 Function not available in ST72F65 TIMERx_Clear_Flag 3 132 235
98. alled Postconditions None None See also SCIx GetString Interrupt driven mode Note This function is only for Polling mode Caution The application can lose control if the SCI is disabled while using this function in poll ing mode 46 235 3 Function Descriptions Table 22 SCIx GetBuffer Function Name Function Prototype SCIx GetBuffer Void SCIx GetBuffer unsigned char PtrToBuffer un signed char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts reception of the bytes and stores it into the user buffer in interrupt driven mode PtrToBuffer Start address of the user buffer NbOfBytes Total number of bytes to be received None Required Preconditions Functions called 1 The SCIx_Mode must have been called 2 You must enable the interrupt due to Receive Data Ready flag 3 You must select the Interrupt driven reception mode in ST7lib_Config h 4 SCIx_IT_Function must have been called inside the SCI interrupt subroutine None Postconditions See also You must call SCIx IsReceptionCompleted after this func tion to check the reception status SCIx GetBuffer Polling mode Note This function is only for Interrupt driven mode Caution Take care not to access the user buffer until reception is completed Any data received before calling this function is ignored The data recepti
99. am using the library functions given in the user manual for each peripheral and compile Caution Only the ST7lib_config h and the files contained in the configuration subdirectory of the examples folder are user modifiable the rest of the source files are write protected Changing peripheral source files and header files may adversely affect the library operations and this will be complicated to update when there are new library releases 6 2 USING THE COMMUNICATION PERIPHERALS LIBRARY 6 2 1 SCI This part of the user manual contains the detailed description of all the functions for the SCI An example C program has been given at the end You can select either of the two Transmission Reception modes of SCI implemented inside the library For selecting any of the possible modes described below you need to select the corresponding define statement inside the ST7lib_Config h file Polling With this mechanism the data can be transmitted or received by polling the status of the cor responding flag Here both the single as well as continuous Transmission Reception is pos sible In continuous Transmission Reception control will be inside the function until all the re quested data is Transmitted Received and hence the application software has the risk of losing control if there is a breakdown in communication the SCI mode is disabled To avoid this risk you can use the single byte transmission with some time out protection inside this m
100. ameters Unsigned char Port Data Returns the data in the port register Reguired Preconditions None Functions called None Postconditions None See also None Note When the IO port is in input configuration and associated alternate function is enabled as an output reading the port DR register will read the alternate function output status Table 169 10 ByteWrite Function Name IO ByteWrite Function Prototype Behaviour Description VoidlO ByteWrite IO Port Port Val4 unsigned char IO ByteData Writes data byte into port register Input Parameter 1 Selects the port name IO PORT X X A B The port name has to selected with reference to the datasheet Reguired Preconditions IO ByteData Input Parameter 2 A Data byte to be written into port register Output Parameters None If you want to write data in output mode IO Output must have been called Functions called None Postconditions None See also None Caution When you write data in a port register in this function the previous data in the port is modified 222 235 3 Function Descriptions Table 170 1O_Write Function Name Function Prototype IO Write VoidlO Write IO Port Port Val3 1O Pin Pin Val3 IO Write Data Data Val Behaviour Description Input Parameter 1 Writes the data into the port pins Selects the port name IO PORT V V A B The port name as per datashee
101. and 1 SCI on all other devices For devices with only one SCI no suffix x is used in the function names For 2nd SCI of ST72F561 you must replace suffix x in the function names with 2 Function Name SCIx Init Void SCIx Init SCI Type Parami Init Value1 SCI Type Param2 Init Value2 Initialization of SCI sets by default receiver sleep off no break character will be transmitted wakeup from sleep by idle frame detection Parity disabled 8 bit transmission mode and Receiver in active mode You can select the parity 9 bit transmission mode Receiver wakeup Receiver Mute and Break Enable fea ture through properly selecting the Init Value1 and Init_Value2 SCI_ODPARITY_SELECT Select odd Parity SCI_EVPARITY_SELECT Select even parity SCI_WAKEUP_ADDR Input Parameter 1 Receiver wake up from mute mode while address mark is detect ed i e MSBit of the data transmitted should be 1 SCI_WORDLENGTH_9 Select 9 bit transmission SCI DEFAULT PARAM1 Load the register with the default value 0x00 SCI MUTE ENABLE Receiver in mute mode SCI BREAK ENABLE Transmit break characters SCI DEFAULT PARAM2 Load the register with the default value 0x00 Output Parameter None Reguired Preconditions SCI port pin should be configured properly Function Prototype Behaviour Description Input Parameter 2 x 34 235 Function Descriptions Table 7 SCIx_Compute_Baudrate Function Name SCIx Compute Baudrate V
102. and TBU counter starts running None Output Parameters Required Preconditions None TBU_SetPrescCount8 or TBU_SetPrescCount16 must have been called Functions called Postconditions None If the TBU interrupt is enabled the control goes into the In terrupt subroutine after the programmed delay time See also Table 136 TBU_ReadCounter None Function Name Function Prototype TBU_ReadCounter Unsigned char TBU_ReadCounter void Behaviour Description Input Parameters Reads the counter register of TBU and returns its current status None Output Parameters Unsigned char Value of the counter register Required Preconditions None Functions called None Postconditions None See also None Table 137 TBU Disable IT Function Name TBU Disable IT Function Prototype Behaviour Description Void TBU Disable IT void Disables the Overflow interrupt Input Parameters None Output Parameters None Reguired Preconditions None Functions called None Postconditions None See also TBU Init 3 189 235 Function Descriptions Table 138 TBU_ClearOverflow Function Name Function Prototype TBU_ClearOverflow Void TBU_ClearOverflow void Behaviour Description Input Parameters Clears the overflow status flag None Output Parameters None Required Preconditions TBU_Enable must have been called
103. ansmission SCI_OVERRUN_ERR Overrun error occurred during reception SCI_FRAMING_ERR Framing error occurred during reception SCI_PARITY_ERR Parity error occurred during reception SCI_RECEIVE_OK Error free reception 1 The SCIx Mode must have been called 2 You must select Polling reception mode in ST7lib_Config h Functions called See also None SCIx GetBuffer Interrupt driven mode Note This function is only for Polling mode Caution The application can lose control if the SCI is disabled while using this function in poll ing mode 3 45 235 Function Descriptions Table 21 SCIx GetString Function Name Function Prototype SCIx_GetString SCI RxError tSCIx GetString unsigned char PtrTo String Behaviour Description Input Parameters Output Parameters Reguired Preconditions Receives and stores the data in the user defined string The reception stops as soon as an error occurs and error status is returned The data reception is controlled by poll ing PtrToString Start address of the String SCI_NOISE_ERR Noise error occurred during reception SCI_OVERRUN_ERR Overrun error has occurred during reception SCI_FRAMING_ERR Framing error occurred during reception SCI_RECEIVE_OK Error free reception SCI_PARITY_ERR Parity error occurred during reception 1 SCIx_Mode must have been called 2 You must select Polling reception mode in ST7lib_Config h Functions c
104. ar SPI_ENABLE_IT unsigned char SPI_BAUDRATE_4 unsigned char SPI_CLK_PP_0 SPI_MSTR_SW SPI Initialised in master software mode Serial peripheral output nabled Interrupt enabled CPOL 0 CPHA 1 and baudrate is 2MHz EnableInterrupts Interrupt mask is reset for enabling interrupt ifdef SPI POLLING TX Single byte data transmission SPI PutByte My Data Templ SPI IsTransmitCompleted while User Timeout Function amp amp Templ SPI TRANSMIT OK Templ SPI IsTransmitCompleted if User Timeout Function switch Temp1 case SPI TX MODF SPI TX WCOL case SPI TX MODF case SPI TX WCOL User Function Error Management break default If none of the above condition is met User Function break Transmission of 10 data bytes from user buffer switch SPI PutBuffer Buff unsigned char 10 case SPI_TX_MODF SPI TX WCOL 3 75 235 Function Descriptions case SPI TX MODF case SPI TX WCOL User Function Error Management break case SPI TRANSMIT OK Transmission is successful break default If none of the above condition is met User Function break endif o oooooooooooooooooooooooooooooooooooooooo oooo Reception through Polling mode ooo o ooo ooooooooooooooooooooooooooooooooooo ifdef
105. ate for SCI without ex tended baudrate prescaler You have to define all the prescaler parameters corresponding to the desired baudrate speed You have to pass the three input param eters by logically ORing them to select the baudrate Input Parameters SCI PR X X 1 3 4 13 SCI TR Y Y 1 2 4 8 16 32 64 128 SCI RR Z Z 1 2 4 8 16 32 64 128 Output Parameter Reguired Preconditions Functions called None 1 SCIx_Init must have been called 2 You have to specify the PR RR and TR values for the desired baudrate None Postconditions Refer to the table below SCI PR 13 SCI TR 2 SCI PR X SCI TRY SCI RR Z Transmitter baudrate Receiver baudrate speed Speed SCI PR 13 SCI TR 1 SCI RR 1 38400 38400 SCI PR 13 SCI TR 4 SCI PR 13 SCI TR 8 SCI RR 2 19200 19200 SCI RR 4 9600 9600 SCI RR 8 4800 4800 SCI PR 13 SCI TR 16 SCI PR 13 SCI TR 32 SCI RR 16 2400 2400 SCI RR 32 1200 1200 Note This function saves the ROM area but you have to pass the values for the TR PR RR 36 235 3 Function Descriptions Table 9 SClx_Extend_Baudrate Function Name SCIx Extend Baudrate Void SCIx Extend Baudrate SCI Baudrate Type Function Prototype Baudrate Prescaler unsigned char EPTR unsigned char EPRR Selects Transmit Receive baudrate for SCI with extended Behaviour Description baudrate prescaler You have to define all the prescaler parameters corresponding to the desired baudrate s
106. ave been called to en sure that there are no pending reguests 4 You must enable interrupts for this mode 5 In 12C Interrupt driven mode I2C IT Function must have been called in the Interrupt service routine Functions called Postconditions None 12C_IsTransmitCompleted can be called after this function to get the transmission status See also I2C PutBuffer I2C Polling mode Note The above function is only for I2C Interrupt driven mode Caution Take care not to access the string until transmission is complete The data transmission will stop if any error occurs during transmission 90 235 3 Function Descriptions Table 53 12C_IsTransmitCompleted Function Name Function Prototype 12C_IsTransmitCompleted 12C_TxErrCode_t12C_IsTransmitCompleted void Behaviour Description Input Parameters Checks for any error during transmission and returns the error status lt also checks for any pending requests None Output Parameters Required Preconditions 12C_TX_AF If Acknowledge failure has occurred I2C TX ARLO If Arbitration lost is detected 12C_TX_BERR If misplaced start or stop condition detected I2C ADD TX OK If there is no error in transmission of address bytes I2C HEADERADD TX OK If there is no error in transmission of header byte I2C START OK If there is no error in start condition generation I2C DATA TX OK If there is no error in
107. both Polling and Interrupt driven Mode But in I2C POLLING RX it is used only with I2Cs GetByte TTA 115 235 Function Descriptions If this function is called before any reception request is made then it will return I2C EMPTY until the first data byte is received and returns the reception status thereafter If a reception request is over this function will return the error status of that request only once Table 74 12Cs_ErrorClear Function Name 12Cs_ErrorClear Function Prototype Void 12Cs_ErrorClear void Behaviour Description Clears the error flags if there are any Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Note You can call this function whenever the error flags are required to be cleared forcibly Caution Do not call this function if a reception request Os ongoing as it will corrupt the recep tion status by clearing all the flags and you will not receive the error status Table 75 12Cs_PeripheralDisable Function Name 12Cs_PeripheralDisable Function Prototype Void 12Cs_PeripheralDisable void Behaviour Description Disables the peripheral Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions You must call 2Cs_Init after this to reconfigure the periph eral See also None Note When you disable the peripheral
108. break endif Communication mode defined as ITDRV WITHOUTBUF TX in ST7lib config h Single byte transmission ifdef I2C ITDRV WITHOUTBUF TX if I2C IsTransmitCompleted I2C DATA TX OK 3 Function Descriptions 3 switch Ensure that there are no pending requests I2C Generate Start while 12C_IsTransmitCompleted I2C START OK I2C Load Address Addr Byte Tx I2C TX MODE Timeoutcount 0 Templ 12C_IsTransmitCompleted while User_Timeout_Function amp amp Temp1 12C_ADD_TX_OK Temp1 12C_IsTransmitCompleted switch Templ To check transmission status case I2C TX AF User Function break default break I2C_PutByte My_Data User data is copied to global variable Here user can perform other tasks or operations except transmission till the time transmission is complete after which user can perform transmission again 12C_IsTransmitCompleted To check transmission status case I2C TX AF case I2C TX ARLO case I2C TX BERR User Function Error Management break case I2C DATA TX OK break default If none of the above condition is true User Function break Transmission of set of data from the user buffer I2C PutBuffer Buff unsigned char 10 User pointer is copied to global pointer Here user can perform other tasks or operations excep
109. ceeded sie olde wee were ae eee eee eens 28 8 1 PERIPHERALS roroku tider eie Eren E coiota det tea 28 82 DEVICES bj a re oo o OE eet ae AN ds 29 9 FUNCTION DESCRIPTIONS 0 2 ccc eee eee 30 9 1 GENERAL PURPOSE PERIPHERALS 0000 eee ee o 30 OA ADE ss ha awe bad yee be B Pi Pewee or Bee 30 O12 OG 2565 tiie beveou ime pete ley o eke ee ee key eee 34 D3 SSP l een nce tie wlan asin 59 Ti IPEMASTER oa Bee letting idas seed added Dista lts Sl Baga 81 915 I2ZC SUAVE ea id eee baie He bie oy Noble a ee wees 107 5 235 ISA Table of Contents 91 65 16 bit TIMER TIME F rtorras Da 124 9 1 7 8 bit TIMER TIMERS 0 Ec wil Bem hades ANE DAREN See eL 137 9 18 CATE TIME etl a cue nerd Sane 150 91 9 PWMART osea a tel iat on oa 159 9 1 10 LITE AUTO RELOAD TIMER LART 0 00 cee eee 171 A BU e RO 187 IMA WDG a TS a Se Pete a oe yo o ony dn 192 QA A EOS 196 9114 MGC ic ia 208 91 15 EEPROM a id onak M rene o o 214 OSE 6 AAA E ES ARR yt AS 219 9 2 APPLICATION SPECIFIC PERIPHERALS 2 0 n n n 227 9 2 1 GAN LIBRARY FUNCTION LIST 0 0000 eee ee ees 227 9 2 1 1 Initialization Services lt es 227 9 2 1 2 Transmit ServiceS lt ees 228 9 2 1 3 Sleep Wakeup Services cee eee 230 9 2 1 4 Status Information Service o ooooooooooooo es 231 9 2 1 5 Transmit Receive Task Services oooooooooo o 231 92 16 InterrUpt SECOS usos A uo eds Be a ES 232 10 A
110. conditions If LART BREAK DISABLE mode is selected then LART ActivateBREAK and LART_DeactivateBREAK functions are called to activate and deactivate the BREAK condition See also LART ActivateBREAK LART_DeactivateBREAK Note This function is available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI de vices 180 235 3 Function Descriptions Table 126 LART_ActivateBREAK Function Name Function Prototype LART_ActivateBREAK Void LART_ActivateBREAK Behaviour Description Input Parameter Generates the software BREAK condition Break pattern is loaded on PWMx pins None Output Parameters Required Preconditions None Break state PWM pattern is loaded using function LART_ConfigureBREAK Functions called Postconditions None LART_DeactivateBREAK must have been called to deac tivate the BREAK condition See also LART_ConfigureBREAK LART_DeactivateBREAK Note This function is available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI de vices Table 127 LART_DeactivateBREAK Function Name LART_DeactivateBREAK Function Prototype Behaviour Description Void LART_DeactivateBREAK Deactivates the the software BREAK condition All LART registers are initialized to reset state Input Parameter Output Parameters None None Required Preconditions Functions called Software BREAK is generated using LART_ActivateB
111. conditions Interrupts or watchdog enabled Functions called None Postconditions See also Input capture interrupt or Timebase interrupt or watchdog disabled depending upon the input parameter passed LT_Init 1 Present in ST7FLITEO and ST7SUPERLITE 2 Present in ST7FLITE1 2 3 and ST7FDALI 3 153 235 Function Descriptions Table 103 LT WDG Reset Function Name Function Prototype LT WDG Reset Void LT WDG Reset Lt Reset Param WDGValue Behaviour Description Input Parameter Delays or forces watchdog reset depending upon the input parameter passed LT DELAY WDG RESET watchdog reset delay by typG 1 LT_FORCD_WDG_RESET force a watchdog reset Output Parameters None Required Preconditions Watchdog enabled Functions called None Postconditions See also Watchdog reset occurred or delayed depending upon the input parameter passed LT_Init 1 typa 2ms 8 MHz fosc therefore You have to use this option at regular intervals to pre vent a watchdog reset occurring Note The function can be used for ST7FLiteO ST7SUPERLITE and ST7FDALI Table 104 LT_ICAP_Getvalue Function Name LT_ICAP_Getvalue Function Prototype Behaviour Description Unsigned char LT_ICAP_Getvalue void Returns the input capture register value Input Parameters Output Parameters Required Preconditions Functions called None Input capture register value as unsigned char
112. configured in master transmitter mode 2 You must define I2C interrupt driven mode in ST7lib_config h 3 12C_IsTransmitCompleted must have been called to en sure that there are no pending requests 4 You must enable interrupt for this mode 5 12C_IT_Function must have been called in the Interrupt service routine Functions called Postconditions None 12C_IsTransmitCompleted can be called after this function to get the transmission status See also 12C_PutString 12C Polling mode Note The above function is only for I2C Interrupt driven mode Caution Take care not to access the string until transmission is complete The data transmission will stop if any error occurs during transmission 3 89 235 Function Descriptions Table 52 12C_PutBuffer Function Name Function Prototype I2C PutBuffer Void 12C_PutBuffer const unsigned char PtrToBuffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts transmission of data from the user defined area for 12C interrupt driven mode PtrToBuffer Start address of the user buffer NbOfBytes Number of data bytes to be transmitted None Required Preconditions 1 12C Load Address must have been called If 12C is configured in master transmitter mode 2 You must define I2C interrupt driven mode in ST7lib_config h 3 12C_IsTransmitCompleted must h
113. consists of the following functions for TBU Function Name TBU Init Function Prototype Behaviour Description Void TBU Init TBU Init Param init value Initialization of the TBU sets by default TBU counter fro zen cascading disabled interrupt disabled and prescaling factor to 2 You can change the default configuration by selecting one or more of the following input parameters Input Parameters TBU DEFAULT Sets TBU to reset value TBU ART CASCADE Cascade the TBU and the PWMART timer counters to gether TBU IT ENABLE TBU overflow interrupt enable Table 133 TBU SetPrescCount8 Function Name Output Parameters None Required Preconditions None Functions called None Postconditions None See also None TBU_SetPrescCount8 Function Prototype Behaviour Description Void TBU_SetPrescCount 8 TBU_Presc TBU_Prescvalue_P unsigned char Counter_Value Selects the prescaler division factor sets the counter val ue Input Parameter 1 TBU_Prescvalue_P where P is the prescalar division factor and it can be 2 4 8 16 32 64 128 256 Input Parameter 2 Counter_Value 8 bit counter value This value can be from 0x00 OxFFh Output Parameters Reguired Preconditions None 1 TBU Init must have been called 2 You have to calculate the values Prescvalue_P and Counter Value for the reguired delay Functions called Postconditions None None See also 3
114. criptions 9 1 14 MCC Function Name Function Prototype MCC Init Void MCC Init MCC Init Init Value Behaviour Description Input Parameters Initialization of MCC By default main clock out MCO al ternate function beep mode and oscillator interrupt are disabled You can change the default configuration by se lecting input parameters given below You can pass one or more parameters by OR ing them MCC DEFAULT Load MCC registers with reset value 00h MCO ENABLE Enables main clock out alternate function MCC IT ENABLE Enables oscillator interrupt Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Note If you want to enable interrupts parameter MCC IT ENABLE has to be passed in the MCC Init function You must then use the Enablelnterrupts macro to reset the Interrupt mask Caution The MCO function is stopped during Active Halt mode 3 208 235 Function Descriptions Table 157 MCC_SlowMode Function Name Function Prototype MCC_SlowMode Void MCC_SlowMode MCC_Mode Slow_Mode MCC Param Config Value Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Selects fepu main clock frequency depending on the input MCC_SLOW_ENABLE Enables slow mode MCC_SLOW_DISABLE Disables slow mode MCC_CLK_0 Selects clock as fogcz This parameter is passed when slow mode
115. de while Time Out amp amp Error Status I2Cs TX DATA OK Error Status I2Cs IsTransmitCompleted switch Error_Status case I2Cs TX AF case I2Cs BERR case I2Cs DEFAULT STATUS case I2Cs STOP DETECTED case I2Cs GENERAL CALL case I2Cs ADDRESS DETECTED User Function break default User Function break ifdef I2C_POLLING_TX Error Status 12Cs_PutBuffer Buff_Out maxsize switch Error Status case I2Cs TX DATA OK case I2Cs OVERFLOW TX break case I2Cs BERR case I2Cs ADDRESS DETECTED case I2Cs GENERAL CALL User Function break default User Function 119 235 Function Descriptions endif break RRRKKEK end of polling mode KEKKKK KA KKK KK KA KKK KK KA K KKK KK fRSESERES INTERRUPT ifde I2Cs_ DRIVEN MODE KKKK KKK KKK A KKK K K KA K KKK K KA KKK K KEE KEKE F I2C ITDRV WITHOUTBUF TX PutBuffer Buff Out maxsize Error Status I2Cs IsTransmitCompleted while I2Cs OVERFLOW TX Time_Out amp amp Error_Status I2Cs TX DATA OK amp amp Error Status Error Status I2Cs IsTransmitCompleted switch Error Status I2Cs OVERFLOW TX case I2Cs BUFF TX ONGOING Error Status I2Cs IsTransmitCompleted while Error Status I2Cs TX DATA OK amp amp Error Status Error Status I2Cs IsTransmitCompleted break case I2Cs TX DATA OK case I2Cs OVERFLOW TX break
116. de ST71ib_config h File for user to select device as ST72F521 Fosc2 as 8MHz protoytpe declaration void MCC_IT_ Routine void void main void void main void MCC initialised Main clock out and oscillator interrupt enabled MCC Init unsigned char MCO_ENABLE unsigned char MCC IT ENABLE EnableInterrupts MCC SlowMode MCC SLOW ENABLE MCC CLK 4 Fcpu selected as 2 MHz MCC RTC Timer MCC RTC 1 Time base selected as 4ms WaitforInterrupt Waiting for interrupt FERRER KKK K KK K K KA K K K K AK KA K KK K K KA KK A K K K K K KA KKK K K KA KKK K K KA KKK kkk k kk k k k k k k k k k k k k k k k Interrupt Service Routine An example of 1kHz beep signal generation in BEEP pin is given which will be executed when RTC interrupt is generated E IAN ifdef _HIWARE_ Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved else ifdef COSMIC Test for Cosmic Compiler interrupt Cosmic interrupt handling else error Unsupported Compiler Compiler Defines not found endif endif void MCC_IT_Routine void MCC Clear IT Clears the interrupt MCC Beep MCC BEEP 2 Generates 1 KHz beep signal 3 213 235 Function Descriptions 9 1 15 EEPROM Following are the functions related to EEPROM Function Name EEPROM Init Function Prototype Void EEPROM nit void Initialization of EEPROM Loa
117. dow value a watchdog reset is gener ated Caution This function is valid only for Window Watchdog if used for normal Watchdog a com pilation error is generated 194 235 ky Function Descriptions EXAMPLE The following C program shows the use of the WDG library functions Program description This program generates the watchdog reset for ST72F521 device The reset timeout period is configured as 34ms with fosc2 8MHz through function WDG Refresh with input parameter Counter Data as 0x50 See Table 141 Watchdog reset timeout can also be configured through WDG_ComputeTimeout function refer to the example below Here it is configured for a reset timeout of 20 000us with input parameter WDG Timeout given as 20 000 In Window Watchdog the reset can be generated by reloading the WDG counter register out side the Window In the example it is generated after 1ms FERRERA K KKK KKK K kkk k kkk kkk k kk k k Program Start EN include ST71ib_config h void main void void main void unsigned int i ee SS 2 22 ee ee ee a 5 gt 2eSi WDG Refresh 0x50 Generates reset after 34ms ee ee 22 22 22 2 gt 5 222222 2202222225 Ss 2 gt 8 WDG_ComputeTimeout function to generate a reset after 20ms MCC timebase 4ms fosc2 8MHz SS SS SS s Se Sie ss E SSE in a Ss o Ss WDG ComputeTimeout 50000 Generates reset after 20ms EES Z EE
118. ds the EEPROM register with reset value 00h Input Parameters None Output Parameters None Selection of the right EEPROM device in the file ST7lib_config h Behaviour Description Required Preconditions Functions called None Postconditions None See also None Notes The EEPROM can enter WAIT mode on execution of the WFI instruction of the microcon troller If programming is in progress then EEPROM will finish the current cycle and then en ter WAIT mode The EEPROM immediately enters HALT mode if the microcontroller executes the HALT in struction Therefore EEPROM will stop the function in progress and the data may be cor rupted 3 214 235 Function Descriptions Table 163 EEPROM_Read Function Name Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 Input Parameter 3 EEPROM_Read For Metrowerks void EEPROM Read unsigned char PtrToUsrBuffer unsigned char NbOfBytes unsigned char far PtrToE2Buffer For Cosmic void EEPROM Read unsigned char PtrToUsrBuffer unsigned char NbOfBytes near unsigned char PtrToE2Buffer Reads data from EEPROM memory and stores it in the user buffer PtrToUsrBuffer User address where data has to be stored NbOfBytes Number of bytes you want to read from EEPROM memory PtrToE2Buffer EEPROM memory address from where data has to be read Output Parameters
119. e 3 42 235 Function Descriptions Table 18 SCIx 9thBit TxRx Function Name Function Prototype SCIx 9thBit TxRx BOOL SCIx 9thBit TxRx BOOL Bit9 Val Behaviour Description Input Parameters Output Parameters Reguired Preconditions Functions called This function configures the 9th bit to be transmitted as 0 or 1 for 9 bit transmission Also it returns the status of the 9th bit in the 9 bit reception mode TRUE If 1 is to be transmitted as 9th bit FALSE If O is to be transmitted as 9th bit TRUE If 9th bit received is 1 FALSE If 9th bit received is 0 1 SCI must be configured in 9 bit mode 2 For reception function SCIx_GetString SCIx_GetBuffer SCIx_GetByte must have been called before this function None Postconditions See also For transmission SCIx PutByte SCIx PutBuffer SCIx PutString must be called after this function None Notes In transmission the return value of the function is ignored In reception the input parameter is not significant You must call this function while using 9 bit mode The Status of the 9th bit remains same during the complete buffer string transmission You can change the status of 9th bit in the next reguest 3 43 235 Function Descriptions Table 19 SCIx_GetByte Function Name Function Prototype SCIx GetByte Unsigned char SCIx GetByte void Behaviour Description Input Parameters
120. e master is receiving ky 19 235 How to use the library For Example if N Bytes to be received r When N 2 byte is received Read I2CDR Wait for BTF 1 When N 1 byte Clear ACK in I2CCR is received Read I2CDR Wait for BTF 1 When N th byte Set STOP in I2CCR is received Read I2CDR In 12C_GetBuffer the ACK and STOP bits are automatically managed inside the function In I2C GetByte you must manage the ACK and STOP bits as shown below in order to receive only one byte 20 235 3 How to use the library Figure 3 Flow Chart for single byte reception in Master mode I2C Load Address send slave address Waiting for completion of event EV6 wait for EVF 1 Read I2CSR1 Clear ACK in I2CCR register by using the function I2C ACK Wait for BTF 1 Set STOP in I2CCR I2C_GetByte 6 2 4 CAN This Section gives an overview of the user guidelines for the CAN Library The library provides the software routines to use the CAN peripheral for ST72F561 device The library is based on the HIS Vector CAN driver specification The implemented function list is a subset of the func tions described in the HIS Vector CAN driver specification document 3 21 235 How to use the library 6 2 4 1 DESCRIPTION Files Can c This file contains the CAN driver source code Can h This file contains the data structure da
121. e1 and input capture2 register values Function Prototype Behaviour Description TIMER8 ICAP I where can be 1 or 2 I 1 Input capture1 register value is returned l 2 Input capture2 register value is returned Input Parameters Input capture1 or Input capture2 register value The re Output Parameters turned value can be in the range 0x00 to OxFC ICF1 and or ICF2 1 Reguired Preconditions You have to call this function after the ICF1 and or ICF2 flag is set to get the capture value Functions called None Postconditions Input capture1 or Input capture2 register value is returned See also TIMER8 ICAP Mode Note The input capture flag gets cleared if this function is called after the TIMER8 Status Flag Y 144 235 Function Descriptions Table 94 TIMER8_Status_Flag Function Name Function Prototype TIMER8_Status_Flag Bool TIMER8_Status_Flag Timer8_Flag FLAG_F Behaviour Description Input Parameters Output Parameters Checks the status of any one of the timer flags depending upon the input parameter The function can be called more than once for checking more than one flag TIMER8_FLAG_F where F can be OCF1 OCF2 ICF1 ICF2 or OVF F OCF1 checks for OCF1 flag F OCF2 checks for OCF2 flag F ICF1 checks for ICF1 flag F ICF2 checks for ICF2 flag F OVF check for OVF flag TRUE or FALSE If TRUE flag is set If FALSE flag is not set Req
122. echanism This mechanism can only be used with the SCI in half duplex mode To use this mode you must have selected the following define labels inside the ST7lib config h file SCI_POLLING_TX For Transmission mode SCI_POLLING_RX For Reception mode For SCI2 in ST72F561 device the labels are SCI2 POLLING TX For Transmission mode SCI2 POLLING RX For Reception mode Interrupt driven without communication buffer With this method data can be Transmitted Received either in single or continuous mode using interrupts In continuous mode the user data is directly being read written from to the ad dresses passed by the user After each byte of data transfer an interrupt is acknowledged and the control goes to the interrupt subroutine The main advantage of using interrupts rather than polling is that control does not stay in the function till the last data is Transmitted Re ceived and hence the SCI can be used in full duplex mode Here you should take care not to read write the user buffer until the Transmission Reception is complete To use this mode you must select the following define labels in the ST7lib config h file SCI ITDRV WITHOUTBUF TX For Transmission SCI ITDRV WITHOUTBUF RX For Reception For SCI2 in ST72F561 device the labels are SCI2 ITDRV WITHOUTBUF TX For Transmission on SCI2 SCI2 ITDRV WITHOUTBUF RX For Reception on SCI2 S72 17 235 How to use the library 6 2 2 SPI SPI This part of the us
123. econditions Unsigned char None Functions called Postconditions None Reads from the AutoReload Register with the specified value which is automatically loaded from the Counter Reg ister when overflow occurs See also LT ARR WriteValue 1 This function is present only in ST7FLite 1 2 3 and ST7FDALI Table 101 LT CNTR ReadValue Function Name Function Prototype LT CNTR ReadValue Unsigned char LT CNTR ReadValue void Behaviour Description Reads the value from the Counter Register Input Parameter None Output Parameters Unsigned char Reguired Preconditions None Functions called None Postconditions None See also LT ARR ReadValue 1 This function is present only in ST7FLite 1 2 3 and ST7FDALI 3 152 235 Function Descriptions Table 102 LT_Disable Function Name Function Prototype LT_Disable Void LT_Disable Lt_Disable_Param DValue Behaviour Description Input Parameter Disables input capture interrupt or Timebase interrupt or watchdog or all of these depending upon the input param eter passed More than one parameter can be passed by logically ORing them together LT_ICAP_IT_DISABLE disables input capture interrupt LT_TB_IT_DISABLE disables Timebase interrupt LT_TB1_IT_DISABLE 2 disables Timebase1 interrupt LT_TB2_IT_DISABLE 2 disables Timebase2 interrupt LT_WDG_DISABLE disables watchdog Output Parameters None Required Pre
124. ed if Err SCI_RECEIVE_OK Nop Reception OK else if unsigned char Err amp SCI NOISE ERR Userfunction if unsigned char Err amp SCI_OVERRUN_ERR Userfunction if unsigned char Err amp SCI_FRAMING_ERR Userfunction if unsigned char Err amp SCI PARITY ERR Userfunction 57 235 Function Descriptions endif Nop FERRERA K KK K K KA K RR K KA K RR ERK ERK KKK KEKE KKK KER KA K KK RR KA K KK K KERR RRR KK EK RE RE k k k k Interrupt Subroutine RRR KKK K KK A KK AK KK KEK KER KK K K KERR KR KKK RK KEK KKK KK K K KA K KK RRE KK ERK EK EKER ER REA ifdef _HIWARE_ pragma TRAP PROC SAVI else ifdef _COSMIC_ interrupt GI _REGS else error Unsupported Compiler endif endif void sci rt void SCI IT Function Test for HIWARE Compiler Additional registers will be saved Test for Cosmic Compiler Cosmic interrupt handling Compiler Defines not found Interrupt function of the library FERRERA RARE RE RRE RR RR RE KARA RARA END OF IGRE KER KARR KE K KA KRK KK KA KKK K RR RE KR KKK JE RRA RR k kk k k k kk ok ok k k k k k kk k k k k k k k k k KA void Userfunction void SCI Forced Clear Flag BOOL User Timeout Function void while Timeoutcount lt 50000 Timeoutcount return TRUE return FALSE 58 235 3 Functi
125. ed mode and compare flag is set whenever the compare oc curs See also None Note If you select Forced compare mode the input parameter 2 will not affect the output waveform and hence you can pass any value between 0x0000 to OxFFFF 126 235 3 Function Descriptions Table 80 TIMERx_ICAP_Mode Function Name Function Prototype TIMERx ICAP Mode Void TIMERx_ICAP_Mode Timer_Icap ICAP I Timer Edge EDGE SELECT Y Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameter Configures the timer to Input capture mode It determines the type of level transition on input capture pins This func tion should be called twice in order to use both ICAP1 8 ICAP2 TIMER ICAP I where can be 1 or 2 1 Input capture 1 is selected 2 Input capture 2 is selected TIMER_EDGE_Y where Y can be 0 or 1 Y 0 Capture occurs at falling edge Y 1 Capture occurs at the rising edge None Required Preconditions Functions called 1 Input Capture pin used must be configured as floating input 2 Only input capture 2 can be used if PWM or OPM is ac tive None Postconditions 1 Timer configured for input capture mode 2 To detect the occurrence of valid edge you can poll the input capture flag using the function TIMERx Status Flag This is in case you have not ena bled the input capture interrupt See also 1 Function not available in ST72F65
126. ed Preconditions 1 ICAP1 pin used must be configured as floating input 2 To get OPM active PWM must be disabled Functions called Postconditions None 1 Input capture flag is set 2 Timer is active in One pulse mode and waveform can be seen on OCMP1 pin 3 Only Input capture2 function can be used See also 1 Function not available in ST72F65 Notes TIMER8_PWM_Mode Flag due to compare cannot be set by hardware but the compare interrupt can be generat ed due to the setting of compare flag ky 143 235 Function Descriptions Only the ICAP2 pin can be used to perform input capture not the ICAP1 pin Take care that the counter is reset each time a valid edge occurs on the ICAP1 pin and capture 1 flag can also generate an interrupt if input capture interrupt is enabled and the instruction rim is used to clear the bit When OPM is used input capture1 register is dedicated to this mode Similarly output compare2 cannot be used as level OLVL2 is dedicated to OPM By enabling the Forced compare mode while OPM mode is enabled the polarity of the OPM Output waveform may change Table 93 TIMER8_ICAP_Getvalue Function Name TIMER8_ICAP_Getvalue Unsigned char TIMER8_ICAP_Getvalue Timer8_lcap ICAP I Returns the input capture1 or input capture register value depending upon the input parameter passed This function should be called twice in order to get both input captur
127. ed will be dummy bytes OxFF As the no of bytes transmitted are more than the maximum size of the buffer Required Preconditions 1 You must define I2C POLLING TX mode in ST7lib_config h 2 12C communication mode must be detected through the 12Cs_GetCommMode Functions called Postconditions None None See also I2Cs GetBuffer I2Cs PutBuffer I2C Interrupt driven mode The maximum size of the buffer is under user control Notes This function is only forI2C POLLING TX mode Here an Acknowledge Failure I2Cs TX AF error is not returned as it is handled internally Caution Control can be lost if 12C is disabled while using this function for 12C Polling mode Overflow condition The overflow bytes neglected through dummy bytes OxFF 110 235 x Function Descriptions Table 67 12Cs_PutBuffer 12C interrupt driver Function Name Function Prototype 12Cs_PutBuffer Void I2Cs PutBuffer unsigned char PtrToBuffer un signed char MaxSize Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts transmission of data from the user defined area by initializing the transmission buffer for I2C ITDRV WITHOUTBUF TX mode PtrToBuffer Start address of the user buffer MaxSize Size of the buffer None Reguired Preconditions Functions called 1 You must define I2C ITDRV WITHOUTBUF TX mode in ST7lib_config h 2 12C commun
128. enerated User can use the I2C interrupt service routine function or he can write his own code inside this routine at his own risk The data transfer syncronisation may be affected if user includes his own code along with 12C ISR function COMMENTS None A A AS V k n o A m A V se EN SA A AS n K A A l ifdef HIWARE Test for HIWARE Compiler pragma TRAP PROC SAVE_REGS Additional registers will be saved else Hifdef COSMIC Test for Cosmic Compiler interrupt Cosmic interrupt handling S72 105 235 Function Descriptions else terror Unsupported Compiler endif endif void I2C User IT Routine void I2C_IT_Function BOOL User_Timeout_Function void while Timeoutcount lt 50000 Timeoutcount return TRUE return FALSE void User_Function void I2C_Error_Clear 106 235 Compiler Defines not found 12C Interrupt service routine function Time out not elapsed Time out elapsed Clears error and status flags 3 Function Descriptions 9 1 5 12C SLAVE This section contains the description of all the functions for I2C slave You can select either of the Transmission Reception modes of I2C implemented inside the library by using the cor responding define statement Figure 4 General Flow Chart For I2C Slave Polling Mode Initialize 12C Wait for Address Select Event Wait for BTF
129. er rupts Functions called None Postconditions None See also None 38 235 IS Function Descriptions Table 11 SCIx IT Disable Function Name Function Prototype SCIx IT Disable Void SCIx IT Disable SCI IT Type SCI IT Param Behaviour Description Input Parameters Output Parameters Disables SCI interrupts SCI IDLE LINE Disable interrupt due to idle frame reception SCI RECEIVE OVERRUN Disable interrupt due to data reception or overrun error SCI TRANSMIT REGISTER READY Disable interrupts triggered when transmit data register is ready to load SCI_FRAME_TRANSMITTED Disable Interrupt due to Transmission completion SCI_PARITY_ERROR Disable Interrupt due to Parity Error None Required Preconditions The baudrate must have been selected Functions called None Postconditions None See also None Table 12 SCIx_Mode Function Name SCIx Mode Function Prototype Behaviour Description Void SCIx Mode SCI Mode Type SCI Mode Param Enables Transmitter Receiver mode of SCI Input Parameter SCI TX ENABLE Enable the Transmitter mode SCI RX ENABLE Enable the Receiver mode Output Parameter Reguired Preconditions None SClx IT Enable must have been called for interrupt mode Functions called Postconditions None None See also None Note To disable the SCI Mode select the SCIx Init function 3 39 235 Function Descriptions
130. er manual contains the detailed description of all the functions for the SPI An example C program has been given at the end The SPI can be used as Single master multiple slaves and multi master systems in full du plex mode This can be configured by using parallel port pins to control the SS pin by software The transfer of master or slave control can be implemented using a handshake method through the I O ports or by an exchange of code messages through the serial peripheral inter face system In order to respect the SPI protocol you must define the configuration setting SPI_SLAVE_CONFIG in ST7lib config h file as shown below in order to be able to transmit data in software slave mode define SPI SLAVE CONFIG To select any of the possible communication modes described below you need to select the corresponding define state ment inside the ST7lib config h file These modes are applicable for all communication pe ripherals SPI SCI and 12C Polling With this mechanism the data can be transmitted or received by polling the status of the cor responding flag Both single and continuous Transmission Reception is possible In the case of continuous Transmission Reception the function keeps control until all the reguested data is Transmitted Received and hence the application software has the risk of losing control if there is a breakdown in communication the SCI mode is disabled To avoid the risk you can use the single byte transmission wi
131. ers of each function are described in de tail in the user manual The functions are coded in C and are compatible with Metrowerks amp Cosmic compilers The ST7 library is MISRA compliant Registry Key is added to provide information on installation path and version 7 235 3 Getting Started with Tools 3 GETTING STARTED WITH TOOLS 3 1 SOFTWARE TOOLS The library functions have been debugged with the ST7 software toolset The ST7 software toolset can be found on the MCU CD ROM or can be downloaded from the ST website http www st com mcu The following versions of the C compilers are used METROWERKS C toolchain version 4 2 5 COSMIC C toolchain version 4 4d A valid license has to be purchased for Metrowerks and Cosmic compilers Free versions with code limitations may also be available check the websites of the two providers for further in formation Note Since Metrowerks was previously known as Hiware both C compilers are compatible 3 2 HARDWARE TOOLS Hardware tools are not required for using the library you can use the STVD7 simulator if it supports the target device check with the latest device documentation However you can use the following Hardware tools for development support ICD based debugging tools like InDart from Softec or R Link ST from Raisonance ST Emulators EMU or DVP ST7232x SK RAIS Starter Kit by Raisonance ST evaluation boards starter kits fo
132. f unsigned char Err amp SCI PARITY ERR Userfunction Rx Data SCI GetByte Corrupted Data Byte received Timeout elapsed else while 1 Transmitter or Receiver having problem PEA SA AL sos5 Buffer Reception El Err SCI_GetBuffer Buff_Recv unsigned char 19 Reception of data in user buffer if Err SCI RECEIVE OK Checks the error status Nop Reception OK else Error Ocurred during reception if unsigned char Err amp SCI NOISE ERR E Userfunction if unsigned char Err SCI_OVERRUN_ERR Userfunction if unsigned char Err amp SCI_FRAMING_ERR 3 55 235 Function Descriptions Userfunction if unsigned char Err SCI PARITY ERR Userfunction endif ifdef SCI ITDRV WITHOUTBUF TX Selects interrupt mode for transmission Interrupt enable when TDRE flag is set SCI Mode SCI TX ENABLE if SCI IsTransmitCompleted SCI_PutByte unsigned char 55 while SCI IsTransmitCompleted SCI PutString Buff user pointer is copied to the global pointer Here user can perform other tasks or operations except transmission till the time transmission is complete after which user can perform transmission again while SCI IsTransmitCompleted endif ifdef SCI ITDRV WITHOUTBUF RX Selects interrupt mode for tran
133. f both PWM and OPM modes are active then OPM will not work In OPM OCMP1 cannot be used for output compare only OCMP2 is available for output compare Input Parameter 1 Input Parameter 2 Input Parameter 3 Input Parameter 4 Output Parameter TIMER_EDGE_X X 0 input capture1 occurs at falling edge X 1 input capture1 occurs at rising edge TIMER_OUTPUT1_F Low level is reflected at the output compare1 pin after suc cessful comparison of output compare register with free running counter TIMER OUTPUT1 R High level is reflected at the output compare1 pin after successful comparison of output compare1 register with free running counter TIMER OUTPUT2 F Low level is reflected at the output compare1 pin after suc cessfully capturing edge at ICAP1 pin TIMER OUTPUT2 R High level is reflected at the output compare1 pin after successfully capturing edge at ICAP1 pin OCR VALUE You can select this value from 0x0000 to OxFFFF None Reguired Preconditions 1 ICAP1 pin used must be configured as floating input 2 To get OPM active PWM must be disabled Functions called Postconditions See also None 1 Input capture1 flag is set 2 Timer is active in One pulse mode and waveform can be seen on OCMP1 pin 3 Only Input capture 2 function can be used TIMERx PWM Mode 1 Function not available in ST72F65 Notes The compare 1 flag can not be set by hardware but the compare i
134. f the microcontroller Table 183 CanGloballnterruptRestore Function Name Function Prototype Input Parameters Output Parameters CanGloballnterruptRestore void CanGloballnterruptRestore void None None Behaviour Description This service enables the interrupt by clearing the global interrupt flag of the microcontroller Table 184 CanCanlnterruptDisable Function Name Function Prototype Input Parameters None Output Parameters None Behaviour Description This service disables all CAN interrupts by ias p changing the CAN interrupt control flags CanCanlnterruptDisable void CanCanlnterruptDisable void Table 185 CanCanlnterruptRestore Function Name Function Prototype Input Parameters Output Parameters CanCanlnterruptRestore void CanCanlnterruptRestore void None None Behaviour Description This service enables all CAN interrupts by chang ing the CAN interrupt control flags 232 235 3 Appendix A 10 APPENDIX A 10 1 SUPPORTED DEVICES AND THEIR PERIPHERALS ALITHAdNSZLS SSALNAZLS s31M321S 8 bit L9SACZLS 94 8 L9SAZLZLS 6 M P H L9SAZZLS 10 bit p9cd2Z1S eALMAZLs GA LMAZLs JDP9GA22U LOv9333Z1 e0c9 sd eZ 1 LOe9eseZ 1 100933321 68311321 se311321 63311321 S331M321 033111321 10 bit 131113218 ar31M321 61311321 SALTA S S S S S S S 08313218 S S S S S S 01313
135. flag You also have to ena ble the interrupt with instruction rim See also TIMER8_IT_Disable Postconditions Table 88 TIMER8_IT_Disable Function Name TIMER8_IT_Disable Void TIMER8 IT Disable Typ Timer8 DITParameter DIT Function Prototype Value Disables the interrupts One or more input parameters can be passed by logically ORing them together TIMER8 OCMP IT DISABLE Disables the output compare interrupts TIMER8 ICAP IT DISABLE Disables the input capture interrupts TIMER8 OVF IT DISABLE Disable the timer overflow interrupt Behaviour Description Input Parameters Output Parameters None Required Preconditions Any Interrupts enabled Functions called None Postconditions Interrupt is masked due to a particular flag See also TIMER8 IT Enable 138 235 IST Function Descriptions Table 89 TIMER8 OCMP Mode Function Name Function Prototype TIMER8 OCMP Mode Void TIMER8 OCMP Mode Timer8 Compare CMP un signed char OCR VALUE Timer8 Olevel OUTPUT L Behaviour Description Input Parameter 1 Input Parameter 2 Input Parameter 3 Configures the timer8 in Output compare or Forced com pare mode depending upon the input parameter passed This function should be called twice in order to get both the compare mode OCMP1 8 OCMP2 TIMER8 OCMP X X 1 output compare1 mode is selected X 2 output compare2 mode is selected TIMER8 FORCDCMP Y Y 1 Forced compare is
136. h level is reflected at the output compare pin after successful comparison of output compare1 register with free running counter TIMER8_OUTPUT2_F Low level is reflected at the output compare pin after suc cessful comparison of output compare2 register with free running counter TIMER8_OUTPUT2_R High level is reflected at the output compare pin after successful comparison of output compare2 register with free running counter OC1R_VALUE You can select this value from 0x00 to OxFC OC2R_VALUE You can select this value from 0x00 to OxFC None Required Preconditions 1 Timer8 correctly configured 2 Timerg8 interrupt due to input capture1 can be used by enabling the input capture interrupt Functions called Postconditions None 1 Timerg8 is active in Pulse width modulation mode and waveform can be seen on OCMP1 pin 2 Output compare interrupt is inhibited See also Notes TIMER8_Init TIMER8_ICAP_Mode Flags for compare1 8 compare2 can not be set by hardware in PWM mode therefore the output compare interrupt is inhibited ky 141 235 Function Descriptions The flag due to capture1 is set by hardware when the counter reaches the output compare2 register value and can produce the timer interrupt if the interrupt for input capture is enabled and the instruction rim is used to clear the bit in CC register By enabling the Forced compare mode or OPM mode while PWM
137. he Watchdog counter This value must be between 0x40 and Ox7f to avoid an immediate re set To get an immediate reset this value can be between 0x00 to Ox3f None Required Preconditions You must precalculate the value of Counter_Data for the desired Watchdog timeout Functions called Postconditions None 1 The Watchdog is activated after this function and can not be disabled except by a reset 2 A Reset is generated after the desired Timeout when Watchdog counter rolls over from 0x40 to Ox3f See Table 141 for some Counter_Data values and corresponding Watchdog Timeout 3 For window watchdog a reset is also generated if this routine is called when the Watchdog counter value is greater than the Window register value 1 1 This condition is valid only for Window Watchdog Notes This function takes less ROM area but you must pass a precalculated Watchdog counter val ue To prevent the Watchdog reset this routine must be called when 1 The Watchdog counter value is greater than 0x3F 2 and lower than the Window register for Window Watchdog The Watchdog for the ST7FLITEO device is integrated with the Lite Timer peripheral Functions for that watchdog are integrated with the Lite Timer library functions 192 235 3 Function Descriptions Table 141 Watchdog Timeout for some Counter_Data values at fosc2 8MHz for ST72F521 device Counter_Data Watchdog Timeout ms Ox3f t
138. ication mode must be detected through the 12Cs_GetCommMode None Postconditions See also 12Cs_IsTransmitCompleted should be called to know the current status of transmission I2Cs PutBuffer I2C Polling mode The maximum size of the buffer is under user control Note The above function is only for I2C ITDRV WITHOUTBUF TX mode Caution Any data transmitted before using this function will be neglected through dummy byte Overflow condition The overflow bytes are neglected through dummy bytes Table 68 12Cs PutByte Function Name Function Prototype I2Cs PutByte Void I2Cs PutByte unsigned char Tx Byte Behaviour Description Input Parameter Output Parameters Transmits single byte on the I2C bus Tx Byte The byte to be transmit on the I2C bus None Reguired Preconditions Functions called 1 12Cs_GetCommMode must have been called before transmitting first byte to check whether the I2Cs TX MODE is selected or not 2 Transmission of previous data has been taken success fully which should be checked through the I2Cs IsTransmitCompleted None Postconditions See also None I2Cs GetByte ky 111 235 Function Descriptions Table 69 I2Cs_IsTransmitCompleted Function Name I2Cs IsTransmitCompleted Function Prototype I2Cs ErrCode tI2Cs IsTransmitCompleted void Returns the current status of I2C in transmission mode for Behaviour Description Single
139. indow register for Window Watchdog S72 193 235 Function Descriptions Table 143 WDG_ReadCounter Function Name Function Prototype WDG_ReadCounter Unsigned char WDG_ReadCounter void Behaviour Description Returns the WDG counter register value Input Parameter None Output Parameter WDG counter register value Required Preconditions None Functions called None Postconditions None Table 144 WDG_ReadWindow Function Name Function Prototype WDG_ReadWindow Unsigned char WDG_ReadWindow void Behaviour Description Returns the value of the window register Input Parameter None Output Parameter Window register value Required Preconditions None Functions called None Postconditions None Caution This function is valid only for Window Watchdog if used for normal Watchdog a compilation error is generated Table 145 WDG_WriteWindow Function Name WDG_WriteWindow Function Prototype Behaviour Description Void WDG_WriteWindow unsigned char Loads the value of the window register which is compared with the watchdog counter Input Parameter Value to be loaded in the Window register This value must be between 0x00 and 0x7F Postconditions Output Parameter None Required Preconditions None Functions called None After this function Watchdog counter value is compared with the new window value If watchdog counter is reload ed outside this win
140. ion The lt hr h is to be included when the actual hardware register are read to clear the flags For configuring the port pins I O library is used KKKKK KKK KKK AK KK AK K KK K KK A KKK K K K IAN ifdef HIWARE Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved telse ifdef _COSMIC_ Test for Cosmic Compiler interrupt nostack else error Unsupported Compiler Compiler Defines not found endif endif voidLT IC IT Routine void unsigned char ICAP Value i i LTICR Clear ICF LT Clear Flag LT FLAG ICF Call only to clear ICF ICAP Value LT ICAP Getvalue Get capture value and also clear ICF IO Write IO PORT B IO PIN 1 IO DATA HIGH Turn ON LED at PB1 for i 0 i lt 100 i Delay Nop Th 157 235 Function Descriptions IO Write IO_PORT_B IO_PIN_1 IO_DATA_LOW Turn OFF LED at PB1 FERRERA KK K KK K K KA K K K K AK KA K KK K K KA KKK K KK K K KA KKK K K KA KKK K K KA KKK K kk kk kkk k RE k k k k k k k k k Use of TimebaseInterrupt service routine User has to write this function and map the interrupt vector in prm filein case of HIWARE or invector xxx c in case of COSMIC An example of LED toggles after every 5 seconds is given This routine is executed when overflow occurs TBF 1 This gets automatically executed when TBF interrupt of the LT is enabled If the same func
141. ion Input Parameters Generate stop condition None Output Parameters Required Preconditions None Transmission or Reception must have taken place Functions called Postconditions None None See also None Note In master mode you must call this function to end data transfer Caution In order to generate the non acknowledge pulse after the last received data byte the ACK bit must be cleared just before reading the second last byte You must call I2C GetBuffer before calling the I2C Generate Stop function or you have to manage non acknowledge pulse Table 63 12C Generate 9Stops Function Name I2C Generate 9Stops Function Prototype Behaviour Description Voidl2C Generate 9Stops void Generate 9 consecutive stop bits to re synchronize I2C bus in a indefinite state Input Parameters Output Parameters None None Reguired Preconditions Functions called When there are problems in communication and 12C bus is in indefinite state None Postconditions See also You must call 12C_Init after this to start I2C operation None Note This function is used only as a recovery measure If the I2C slaves are powered sepa rately or the MCU was reset during an 12C transmission the 12C bus can be in an unknown state In this case this function can be used to re synchronise the I2C This routine must be called only one time after the MCU was reset Caution The port
142. ion is called again before making next reception request then the function will check for single byte reception Table 58 12C IT Function Function Name I2C IT Function Function Prototype Behaviour Description Void I2C IT Function void Transmits or receives data in I2C interrupt driven mode You must call this function in the interrupt service routine Input Parameters Output Parameters None None Required Preconditions Functions called You must have called transmission or reception function in 12C interrupt driven mode Postconditions See also None Note You must use this function only inside the Interrupt service routine Caution Special care must be taken when you write your own code along with this function inside the interrupt service routine As all I2C interrupt driven functions rely on this function you are advised to call only this function in Interrupt service routine Otherwise data transfer synchronisation will be affected which may lead to data loss or errors Table 59 I2C Error Clear Function Name Function Prototype I2C Error Clear Voidl2C Error Clear void Behaviour Description Input Parameters Clear the error flags if there are any None Output Parameters Reguired Preconditions None Transmission or Reception should have taken place be fore calling this function Functions called None Postconditions None See also N
143. irectory 4 Update the useful paths and link the chosen peripherals files The source path will refer to the directory where ST7_LIBxis installed For example assuming that you have installed ST7_LIBxin DA a The following paths will be updated for Metrowerks in the Default env ST7LIB_PT Change this path to installation of library TOOL_PT Change this path to Metrowerks toolchain path Depending on the peripherals required for the application update the object list in prm and mak files b The following paths will be updated for Cosmic in mak file Update the source path PATHC Change this path to cosmic toolchain installation path LIB PT Change this path to library installation path SRx PT LIB_PT peripherals periph C where x is the no of source path for each peripheral where periph is the name of the peripheral used in the application Update the include path CFLAGS mods debug co OBJ PT i SRx PT where x is the no of source path for each peripheral give the path of all the peripherals present in the particular device Update the source list SRC LIST OBJ_PT source main c SRx PT where x is the no of peripheral used 5 Modify ST7lib config h file to include the target device CPU frequency and the communi cation mode if any of the communication peripherals is used 6 Include ST7lib_config h in main c 16 235 3 How to use the library 7 Write the application progr
144. is a transmit message structure referenced for the CAN driver service CanMsgTransmit 6 2 4 4 MEMORY USAGE Constants This includes the initialization values inside the Init Structure for the CAN controller registers transmit message information tx_id tx dlc inside the transmit structure and receive mes sage information rx_dlc These are stored in ROM Global Variables These include the transmit amp receive buffers confirmation amp indication flags pointers to the Tx amp Rx buffers and receive message id s rx_id 6 2 4 5 PARAMETER CONFIGURATION There are certain parameters that you have to configure depending on the application These parameters are configured inside the files user c amp user h The following are the parameters that must be configured in the file user h 1 NO_OF_TX_HANDLES This parameter defines the number of messages to be trans mitted by the application 2 NO_OF_RX_HANDLES The number of messages to be received by the application which depends on the number of messages configured in the filter registers 3 NO_OF_INIT_HANDLES The number of initialization structures required in an application By default its value is set to 1 ky 23 235 How to use the library 4 TX_MSGx_STDID The standard id part for the MSGx to be transmitted where x transmit message number 5 TX_MSGx_EXTID The extended id part for the MSGx to be transmitted where x transmit message number 6
145. ission or the slave address from where data to be trans mitted in case of reception this function has to be called again See also Y None 85 235 Function Descriptions Table 48 12C_PutByte Function Name Function Prototype 12C_PutByte Void 12C_PutByte unsigned char Tx Data Behaviour Description Input Parameters Output Parameters Transmits a single byte of data in I2C Polling or I2C Inter rupt driven mode Tx_Data Data byte to be transmitted None Required Preconditions 1 12C Load Address must have been called If 12C is configured in master transmitter mode 2 You must define I2C Polling or I2C interrupt driven transmission mode in ST7lib config h 3 You must enable interrupts in I2C interrupt driven mode 4 In 12C interrupt driven mode 12C_IsTransmitCompleted must have been called to en sure that there are no pending requests 5 In 12C Interrupt driven mode I2C IT Function must have been called in the Interrupt service routine Functions called Postconditions None 12C_IsTransmitCompleted can be called after this function to get the transmission status See also Notes None The above function is for I2C Polling or 12C Interrupt driven mode It is recommended to add a timeout protection when using this function 86 235 3 Function Descriptions Table 49 12C_PutString Function Name Function Prototype 12C_P
146. k Watchdog Electrically Erasable Prog Read Only Memory Interrupt Controller Input Output Ports Pulse Width Modulation Auto Reload Timer Time Base Unit 16 bit Timer 8 bit Timer Lite Timer Lite Auto Reload Timer ST Visual Debug 7 Microcontroller Division Periph All names starting with Periph are referring to the name of the peripheral November 2005 Rev 4 0 Table of Contents INTRODUCTION n cts tat AIR A AE CEA A AAA 3 1 1 ABBREVIATIONS USED lt 2 53 sa RR n KK n NA vere on l seas 3 1 2 NAMING CONVENTIONS 0 00 e eee eee eee 3 2 OVERVIEW 350 cn cewze ta da oa B AAA See aces tenes Res 7 2 1 FUNCTIONAL SCOPE cusco 7 2 2 FEATURES lt a sate cas Sours a wea an 7 3 GETTING STARTED WITH TOOLS 2000 eee 8 3 1 SOFTWARE TOOLS jcc 2ncicnct ie ti eles eee E above 8 3 2 HARDWARE TOOLS in tcc dec sara t esto bo Beana a E ea 8 3 3 TECHNICAL LITERATURE 5835 cdo iaa es 8 3 4 HOW TO INSTALL THE LIBRARY ooococoococcn n 9 4 LIBRARY STRUCTURE 25056 m s kot id sask aa 10 4 1 STA LIBX Si Oe 10 4 2 ST EIB CONFIG H cian itv 10 4 2 1 User part of the ST7lib_config h lt 11 4 2 2 Non User part of the ST7lib_config h 2 11 4 3 PERIPHERALS LIBRARY oocccccc eee eee 11 4 3 1 Peripherals directory eect Di e ato v 11 43 2 Periph directory 2 sek ta zk dob a a ea Shee 11 4 3 2 1 AO AMRO O O NA O O 12 4 4 DEVICES book then ra ooo Oct o ooo eens 12 4 5 DOCUMENTA
147. k is configured correctly See also None Note Timer B available in ST72F521 ST72F264 ST72325 and ST7232A 3 124 235 Function Descriptions Table 77 TIMERx_IT_Enable Function Name TIMERx_IT_Enable Void TIMERx_IT_Enable Typ_Timer_ElTParameter ElTVal ue Enables the timer interrupts One or more input parameters can be passed by logically ORing them together TIMER_OCMP_IT_ENABLE Enables the output compare interrupts TIMER_ICAP_IT_ENABLE Enables the input capture interrupts TIMER_OVF_IT_ENABLE Function Prototype Behaviour Description Input Parameters Enables the timer overflow interrupt Output Parameters Required Preconditions Functions called None a2 Interrupts are enabled for a particular flag You also have to en Postconditions ae BAU Aa able the interrupt with instruction rim See also TIMERx_IT_Disable 1 Not available in ST72F65 Note Timer B available in ST72F521 ST72F264 ST72325 and ST7232A Table 78 TIMERx_IT_Disable Function Name TIMERx_IT_Disable Void TIMERx_IT_Disable Typ_Timer_DITParameter DIT Value Function Prototype Disables the interrupts One or more input parameters can be passed by logically ORing them together TIMER_OCMP_IT_DISABLE Disables the output compare interrupts TIMER_ICAP_IT_DISABLE Disables the input capture interrupts TIMER_OVF_IT_DISABLE Disable the timer overflow interrupt Behaviour Description
148. le contains a declaration of the register variables of st7xx for Metrowerks and definitions of the register variables for the Cosmic compiler st7xx reg c This file contains definitions of the register variables of st7xx device st7xx_periph h This file is used to select which peripherals of st7xx device are used in the application 2 Contains the generic configuration files both Metrowerks and Cosmic compilers Metrowerks Contains the mapping file ST72xxx prm for all the hardware registers in de vice Make file ST72xxx mak to build the application and the default env which defines all the useful paths and options for the application COSMIC make file to build the application ST72xxx mak link file ST72xxx Ikf used to link the device and the interrupt mapping file vector xxx c for the target device Notes 1 This software covers 13 main devices and their subsets You have to include the file from the main device section in order to support the related subsets 2 The register files in the ST7 library are different from those provided with the STVD7 ver 3 x Take care to include the correct one 3 12 235 Library Structure Table 1 Supported devices Main device Subsets ST72F62 ST72F621 ST72F622 ST72F623 ST72F611 ST72F63B ST72F63BK1 ST72F63BK2 ST72F63BK3 ST72F65 ST72F65 ST72F521 ST72F521 ST72F321 ST72F324 ST72325 ST72F325 C J K 4 ST72F325 AR C J K 6 7 9 ST7232A ST72F32AK2 ST7FLITEO ST7FLITEO5
149. level is low for Counter value lt Dutycycle Data Input Parameter 3 Output Parameters Dutycycle Data Data to be loaded in Duty cycle register 0x000 to OxFFF Note This value must be greater than the ATR register value loaded through Input parameter 1 to obtain signal on PWMO pin None Reguired Preconditions Functions called LART Init must have been called to select the counter clock None Postconditions PWM signal of reguired freguency and duty cycle is gen erated at PWMO pin The output compare mode is disa bled See also Notes LART Init LART ConfigurePWM This function can be used only with ST7FLiteO devices This function is used to keep backward compatibility with previous library For new develop ment LART_ConfigurePWM function should be used with the first parameter LART_PWMO in place of this function ky 173 235 Function Descriptions Table 118 LART_ConfigurePWM Function Name Function Prototype LART_ConfigurePWM Void LART_ConfigurePWM Lart_PWMChannel PWM Channel unsigned int Autoreload_Value Lart_Output POLARITY unsigned int Dutycycle Data Behaviour Description Generates PWM on PWMx pin The PWM signal frequen cy is controlled by counter clock period and ATR register value Input parameter 1 The PWM signal duty cycle de pends upon input parameter 2 and input parameter 4 Input Parameter 1 Input Parameter 2 Inp
150. libx Peripherals Description This directory contains subdirectories by the name of the peripheral Subdirectory names ADC EEPROM I2C I2CSlave IO ITC LART LT MCC PWMART SCI SPI TBU TIMER TIMER8 WDG CAN 4 3 2 Periph directory Location ST7_libx Peripherals Periph sources TTA 11 235 Library Structure Description Each subdirectory contains a C sub folder which contains peripheral library files 4 3 2 1 C directory Location ST7_libx Peripherals Periph sources C Description Each subdirectory contains the source files header files and an example folder showing the usage of the functions Files Periph c Periph h Periph_hr h Periph c Inclusion of periph_hr h periph h ST7lib_config h It contains the Peripheral functions with some conditional compilation options Periph h This contains the typedef enum parameters for each peripheral prototypes of functions de fined in Peripheral c and definition of Peripheral constant definitions Periph_hr h This file contains the bit mapping of the hardware registers used for the peripherals 4 4 DEVICES Location ST7_LIBx Devices Description 1 Contains the files which define all registers for each device and includes the file which is used to select peripherals for the application This register file is included in the ST7lib_config h The folder ST7_LIBx Devices ST7xx contains st7xx_reg h st7xx_reg c and st7xx_periph h files st7xx_reg h This fi
151. lled None Postconditions None See also None 1 IT LEVEL 0 can not be written 2 These Interrupts do not have an Exit from HALT mode capability Notes This function is for ST72F521 ST72F561 ST72F65 ST72F62 ST72F264 ST72325 and ST7232A devices ky 197 235 Function Descriptions For selecting different priorities for different interrupts you must call the function more than once If it is required to set two or more interrupts to same priority level then you can pass them together by logically ORing This function is for Nested Interrupts only Caution If you select an interrupt which is not present in the Peripheral then you will get an error mes sage during compilation If the Priority of the Interrupt is changed while it is being executed then the following behav our has to be considered If that interrupt is still pending and the new software priority is higher than the previous one the interrupt is re entered Otherwise the software priority stays unchanged until the next in terrupt request Table 148 ITC_Get_CurrentLevel Function Name ITC Get CurrentLevel Function Prototype ITC LEVELITC Get CurrentLevel void Behaviour Description Eu Interrupt software priority level of the current Input Parameters None IT LEVEL 0 Software Priority of the current interrupt is at LevelO IT_LEVEL_1 Output Parameters Software Priority of the current interrupt is at Level1 IT_LEVEL_2
152. lnterrupts macro to reset the Interrupt mask 2 For single master I2C to configure I2C in master mode you have to calll2C Generate Start after this function See also None Note If you select I2C Interrupt driven communication mode interrupts must be enabled dur ing initialization 3 81 235 Function Descriptions Table 44 12C_MultiMaster_Config Function Name Function Prototype I2C MultiMaster Config Void l2C MultiMaster Config void Behaviour Description Input Parameters Configures 12C as multimaster I2C device None Output Parameters Required Preconditions Functions called None 1 ST72F521 ST72F63B ST72325 devices must be se lected for multimaster 12C 2 12C_Init must have been called None Postconditions See also 12C is configured in slave mode To configure in master mode you have to calll2C Generate Start after this None This is only valid for ST72F521 ST72F63B ST72325 devices The input parameter which was available in earlier versions of ST7 library has been removed 82 235 3 Function Descriptions Table 45 12C Select Speed Function Name Function Prototype I2C Select Speed Voidl2C Select Speed I2C Speed Param Speed Value unsigned intI2C Speed Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Selects the I2C clock speed both in standard and fast speed modes I2C D
153. mately as foscz 8000 50 duty cycle MCC_BEEP_3 Selects beep signal approximately as foscz 16000 50 duty cycle Output Parameters None Required Preconditions MCC Init must have been called Functions called None Postconditions None See also None Note The beep signal is available in ACTIVE HALT mode but has to be disabled to reduce the consumption 3 211 235 Function Descriptions Table 161 MCC Clear IT Function Name Function Prototype MCC Clear IT Void MCC Clear IT void Behaviour Description Clears oscillator interrupt flag Input Parameters None Output Parameters None Reguired Preconditions None Functions called None Postconditions None See also Table 162 MCC IT Disable MCC RTC Timer Function Name Function Prototype MCC IT Disable Void MCC IT Disable void Behaviour Description Input Parameters Disables oscillator interrupt None Output Parameters None Required Preconditions None Functions called None Postconditions None See also MCC Init 212 235 ki Function Descriptions EXAMPLE The following C program shows the use of the MCC functions Program Description This program configures fepu main clock frequency as 2 MHz oscillator interrupt timebase as 4ms and generates 1 KHz beep signal o oooooooooooooooooooo o o o ooo o Program Start tinclu
154. me between PWMO and PWM1 This is required for Half bridge driving Input Parameter Output Parameters DTValue 7 Bit value for dead time to be inserted between PWMO and PWM1 dead time DTValue TCounter None Required Preconditions PWMO and PWM1 are configured by calling LART_PWM_Mode Half bridge driving is possible only if Polarities of PWMO and PWM1 are not inverted otherwise overlapping signal will be generated Functions called Postconditions None Dead time is inserted between PWMO and PWM1 signals See also LART_PWM_Mode Note This function is available only for the ST7FLite3 device 3 184 235 Function Descriptions EXAMPLE The following C program shows the use of the LART functions Program description This program generates a PWM signal with a 10KHz frequency and with a 30 Duty cycle and toggles an LED every second Fcpu 8MHZz Program start include ST71ib_config h Select ST7FLITEO prototype declaration void LART_OVF_IT_Routine void void main void static unsigned int count void main void IO Output IO PUSH PULL IO PORT B IO PIN 3 Port PB3 as pushpull output Select Fcpu as counter clock enable overflow interrupts El LART_Init unsigned char LART_COUNTER_CLK_FCPU unsigned char LART_OVF_IT_ENABLE Clear I bit in CC register EnableInterrupts Load ATR and DCR to get PWM signal of 10 KH
155. mebase for Timebase for Timebase for Timebase for MCC RTC X foscz 1MHz fosc2 2MHz fosc2 4MHz fosce 8MHz MCC RTC 0 16ms 8ms 4ms 2ms MCC RTC 1 MCC RTC 2 MCC RTC 3 200ms 100ms 50ms 25ms Notes The timebase for other foscz can be reached by calculation as shown below For MCC RTC 0 Timebase 32000 2 fogco For MCC RTC 1 Timebase 64000 2 fosc gt For MCC RTC 2 Timebase 160000 2 fosc gt For MCC RTC 3 Timebase 400000 2 fosc gt For example if foscz 5MHz for the MCC RTC X input values the timebase values are as follows ForMCC RTC 0 Timebase 3 2 ms ForMCC RTC 1 Timebase 6 4 ms ForMCC RTC 2 Timebase 16 ms ForMCC RTC 3 Timebase 40 ms 210 235 3 Function Descriptions Table 159 MCC_ActiveHalt Function Name Function Prototype MCC_ActiveHalt Void MCC_ActiveHalt void Behaviour Description Enables oscillator interrupt and enters into ACTIVE HALT power saving mode Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions None See also MCC Init Table 160 MCC Beep Function Name MCC Beep Function Prototype Void MCC Beep MCC Beep Param Beep Value Behaviour Description Input Parameters Selects the Beeper output signal by selecting one of the below parameters MCC BEEP 1 Selects beep signal approximately as foscz 4000 50 duty cycle MCC_BEEP_2 Selects beep signal approxi
156. mode SPI IT Function must have been called in the Interrupt service routine Postconditions You can call SPI_IsTransmitCompleted after this function to get the transmission status See also Notes SPI IsTransmitCompleted SPI PutBuffer SPI Polling mode The above function is only for SPI Interrupt driven mode For transmission in software slave mode you must define SPI SLAVE CONFIG in ST7lib_config h Caution Do not access the string until transmission is completed Data transmission will stop if any error occurs during transmission 3 65 235 Function Descriptions Table 35 SPI_IsTransmitCompleted Function Name Function Prototype SPI_IsTransmitCompleted SPI_TxErrCode_t SPI IsTransmitCompleted void Behaviour Description Input Parameters Checks for errors checks for pending requests and re turns the transmission status None Output Parameters SPI_TX_WCOL If write collision error occurs SPI_TX_MODF If master mode fault occurs SPI_TRANSMIT_OK If there is no error in transmission and all data bytes are transmitted SPI_TX_BUFFER_ONGOING If all the data bytes from user buffer are not transmitted SPI_TX_STRING_ONGOING If the complete string is not transmitted Required Preconditions None Functions called None Postconditions None See also None 1 These Parameters are returned in SPI Interrupt driven mode only
157. n cause an unexpected value at the input of the alternate pe ripheral 220 235 TA Function Descriptions Table 167 10 Output Function Name Function Prototype IO Output Void 10_ Output IO Output Mode Output Val lO Port Port Val2 IO Pin Pin Val2 Behaviour Description Input Parameter 1 Configures the I O ports in output mode Refer to the da tasheet to select the output mode and output port name Selects the output mode by selecting one of the below pa rameters IO OPEN DRAIN Selects open drain output mode IO PUSH PULL Selects push pull output mode Input Parameter 2 Input Parameter 3 Selects the port name IO PORT R R A B The port name has to selected with reference to the datasheet Selects port pin number Here you can select more than one pin number by OR ing them IO PIN S S 0to7 Output Parameters None Reguired Preconditions None Functions called None Postconditions See also You must call IO Write after this function if you want to write data in the port register None 3 221 235 Function Descriptions Table 168 10 Read Function Name Function Prototype IO Read Unsigned char IO Read IO Port Read Val Behaviour Description Reads the port and returns the value Input Parameters Selects the port name IO PORT U U A B The port name has to selected with reference to the datasheet Output Par
158. n completion Because of this correct full duplex communication will be prevented In order to operate the SPI in Full Duplex Mode it is required that either the 18 235 ky How to use the library Transmission or Reception is performed in Polling Mode and the other in Interrupt Driven Mode So you can use any one of the following combinations in full duplex mode SPI POLLING TX For Transmission mode SPI ITDRV WITHOUTBUF RX For Reception or SPI ITDRV WITHOUTBUF TX For Transmission SPI POLLING RX For Reception mode 6 2 3 12C This part of the user manual contains the detailed description of all the functions for 12C An example C program has been given at the end You can select either of the two Transmission Reception modes implemented in the library To select any of the possible modes described below you need to select the corresponding define statement inside the ST7lib config h file Polling With this mechanism the data can be transmitted or received by polling the status of the cor responding flag Either single or continuous Transmission Reception is possible In contin uous Transmission Reception control stays inside the function until all the requested data is Transmitted Received and hence the application software risks losing control if there is a breakdown in communication if the 12C mode is disabled To avoid the risk the appplication can use single byte transmission with some timeout protection Thi
159. n side a loop This function should have the Boolean return i e it should return TRUE if the expected wait Time is not elapsed and FALSE if it is elapsed Software Control Wait loop User timeout Function k The following variables are declared in main h file main h ifndef MAIN define MAIN void Userfunction void Declaration of user function BOOL User_Timeout_Function void void sci_rt void endif 3 53 235 Function Descriptions Program start include ST71ib_Config h List of all ST7 devices and communication mode tinclude main h Declaration of all the functions used in main c define Buf_Size unsigned char 20 void main void static unsigned int Timeoutcount unsigned char Buff Rov 20 yo void main void unsigned char Rx_Data 0 unsigned char NbOfBytes 20 unsigned char Tx Data 51 unsigned int BaudRate_Tx 9600 unsigned int BaudRate_Rx 9600 SCI_RxError_t Err 0 unsigned char Buff Buf_Size SCI DRIVERS TESTING user buffer unsigned char new n r BOOL Bool Templ BOOL Bool_Temp2 Timeoutcount 0 SCI Init SCI DEFAULT PARAM1 SCI DEFAULT PARAM2 SCI Compute Baudrate BaudRate_Tx BaudRate_Rx Selects the transmission reception baudrate as 9600 SCI Extend Baudrate SCI PR 13 SCI TR 2 SCI RR 2 0x02 0x02 Selects transmission reception baudrate as 9600 EnableInterrup
160. n will be through polling or interrupt driven modes depending on the mode you selected PtrToString Start address of the user string Output Parameters None 1 SCIx Mode must have been called 2 You must enable the interrupt due to Transmit Data Ready Flag for Interrupt driven mode Reguired Preconditions 3 You must select the transmission mode Polling or In terrupt driven in ST7lib Config h 4 SCIx IT Function must have been called inside the SCI interrupt subroutine Input Parameters Functions called SCIx IsTransmitCompleted Postconditions None See also None Note This function is for Polling or Interrupt driven mode Caution The application can lose control if the SCI is disabled while using this function in polling mode Take care not to access the string until transmission is complete Table 17 SCIx_IsTransmitCompleted Function Name SCIx IsTransmitCompleted Function Prototype BOOL SCIx IsTransmitCompleted void Checks for the completion of data transmission It returns Behaviour Description FALSE till all the data bytes have been transmitted and TRUE when the reguest is over Input Parameters None Output Parameters Boolean Reguired Preconditions Transmission must have been reguested Functions called None Sn SCIx PutByte SCIx PutBuffer SCIx PutString must be Postconditions i called after this function See also None Note This function is for Interrupt driven mod
161. nabled You can call LT_WDG_Reset to de lay or force the watchdog reset LT_WDG_Reset Note This function works only for ST7FLITEO and ST7SUPERLITE 150 235 3 Function Descriptions Table 98 LT_TB Function Name Function Prototype LT_TB Void LT_TB Lt_TB_Param TBValue Behaviour Description Sets Timebase to 1ms or 2ms depending upon the input parameter passed LT_SET_TB_1 Ur mein sets Timebase 1ms LT_SET_TB_2 sets Timebase 2ms Output Parameters None Required Preconditions None Functions called None Postconditions See also Timebase selected is 1ms or 2ms depending upon the in put parameter passed LT_Init Table 99 LT_ARR_WriteValue Function Name LT_ARR_WriteValue Function Prototype Behaviour Description Void LT_ARR_WriteValue unsigned char Loads the specified value in the AutoReload Register Input Parameter Unsigned char value from 0x00 to OxFF Output Parameters None Required Preconditions None Functions called None Postconditions None See also LT_ARR_ReadValue 1 This function is present only in ST7FLite 1 2 3 and ST7FDALI 3 151 235 Function Descriptions Table 100 LT ARR ReadValue Function Name Function Prototype LT ARR ReadValue Unsigned char LT ARR ReadValue void Behaviour Description Input Parameter Reads the value from the AutoReload Register None Output Parameters Reguired Pr
162. nd options for the application COSMIC Contains the make file for building the application ST72xxx mak the link file ST72xxx Ikf used to link the device and the interrupt mapping file vector xxx c for the target device Object Folder These folders are used for temporary storage of object and executable files generated by the compiler in respective directories metrowerks and cosmic 5 2 2 STVD7_3x This folder contains relevant Cosmic and Metrowerks workspace for ST7 Visual Debug ver 3 X as the configuration files are automatically generated 5 2 3 winIDEA only for ST72F561 and CAN peripheral This folder contains relevant configuration files for winIDEA Subdirectories Config Object For details related to Subdirectories refer to Section 5 2 1 3 15 235 How to use the library 6 HOW TO USE THE LIBRARY The next section gives the standard procedure to be followed for all the peripherals Some specific instructions are given in the section 7 2 which have to be followed if you use the com munication peripherals 6 1 STANDARD PROCEDURE FOR ALL PERIPHERALS Note This section is only applicable if you are using STVD7 v2 x 1 Install ST7_LIBxin one directory as per the installation procedure 2 When starting for the first time copy the structure from the demo directory 3 Choose the target device and copy the configuration files for Metrowerks or Cosmic from the devices directory into the user configuration d
163. ndle lt transmitObject gt Input Parameters Output Parameters Behaviour Description Required Preconditions transmitObject Selected transmit Handle KCANTXOK If the transmit request is accepted by the CAN driver KCANTXFAILED If the transmit request is not accepted by the CAN driver This service initiates the transmission within the CAN controller for the CAN message referenced by lt transmitObject gt If any transmit mailbox is empty the transmit process is initiated and KCANTXOK is returned The message informa tion message ID DLC data is taken from the transmit message table referenced by transmit handle lt transmitObject gt and it is copied into the transmit registers lf message is transmitted suc cessfully the confirmation flag is set for this mes sage inside the transmit interrupt routine CanTx ISR Transmit process is initiated and If none of the mailbox is empty or the lt transmitOb ject gt is out of range then transmit process is not initiated and KCANTXFAILED is returned This service shall not be called when the CAN driver is in stop or sleep mode Table 174 CanCancelTransmit Function Name CanCancelTransmit Function Prototype Input Parameters void CanCancelTransmit CanTransmitHandle lt txHandle gt Output Parameters Behaviour Description txHandle Selected transmit Handle None This service cancels a transmit request by mak ing an Abort
164. ne You must have called transmission or reception function in Interrupt driven mode Functions called Postconditions None Communication is started inside the interrupt subroutine See also None Note Only use this function in the Interrupt service routine Caution Special care must be taken while you write your own code along with this function in the interrupt service routine otherwise data transfer synchronisation could be affected which may lead to data corruption 50 235 3 Function Descriptions Table 27 SCI2_Clkout_Enable Function Name Function Prototype SCI2 Clkout Enable Void SCI2 Clkout Enable void Behaviour Description This function enables the ClockOutput of SCI2 of ST72F561 device Postconditions Input Parameters None Output Parameters None Required Preconditions None Functions called None SCI clock is availaible at a dedicated pin during communi cation See also 3 None 51 235 Function Descriptions Table 28 SCI2_CIkConfigure Function Name Function Prototype SCI2_CIkConfigure Void SCI2_CIkConfigure SCI_PO_PH_t SCI_PO_PH_Param SCI_LBCL_t SCI_LBCL_Param Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Configures the Polarity Phase and numbers of Clock pulses for the SCI2 Clock out SCI PO LOW PH LOW Default value on CLK pin low CLK activated at the in the middle
165. neration or digital output CAN The Controller area Network peripheral allows communication over a CAN network 3 28 235 Release Information 8 2 DEVICES ST72F62 ST72F63B ST72F65 ST72F521 ST7FLITEO ST7FLITE1 ST7FLITE2 ST7FLITES ST72F264 ST72F561 ST7SUPERLITE T72325 ST7232A 29 235 3 Function Descriptions 9 FUNCTION DESCRIPTIONS 9 1 GENERAL PURPOSE PERIPHERALS 9 1 1 ADC This software library consists of the following functions for 8 bit and 10 bit ADC Function Name ADC Init Function Prototype Void ADC Init Typ ADC InitParameter InitValue Initialization of the ADC sets by default channel to AINO speed to default value of the device ADC off amplifier off Behaviour Description interrupt disable and Continous conversion mode You can pass one or more input parameters by logically ORing them together to change the default configuration ADC SPEED Fadc Fcpu 4 or Fcpu 2 or Fcpu depending upon the de vice selected ADC_SLOW 2 It is used together with ADC_SPEED to configure ADC clock for device ADC_ONESHOT One shot conversion active ADC_AMPLIFIER_ON Amplifier on ADC_DEFAULT sets ADC in default configuration ADC_IT_ENABLE Interrupt enable for end of conversion Output Parameters None 1 Configure IO properly 2 Selection of the right ADC in the file ST7lib_config h Input Parameters Req
166. nnel must have been called None Postconditions See also ADC conversion started ADC Disable 3 31 235 Function Descriptions Table 4 ADC_Test_Conversn_Complete Function Name Function Prototype ADC_Test_Conversn_Complete BOOL ADC_Test_Conversn_Complete void Behaviour Description Input Parameters Returns the latest status of conversion None Output Parameters TRUE conversion completed FALSE conversion not completed Required Preconditions Functions called ADC_Enable must have been called None Postconditions If TRUE ADC conversion is complete and you can call the ADC_Conversn _Read If FALSE ADC conversion not completed This function can be looped until the conversion is com plete See also Table 5 ADC_Conversn_Read ADC_Disable ADC_Conversn_Read Function Name Function Prototype Behaviour Description ADC_Conversn_Read For 10 bit ADC unsigned int ADC_Conversn_Read void For 8 bit ADC unsigned char ADC_Conversn_Read void Reads the converted digital value from the data register Input Parameters Output Parameters None Data Register value it depends upon the device selected please refer to the corresponding data sheet Required Preconditions Functions called ADC_Test_Conversn_Complete must have been called None Postconditions 1 EOC flag is cleared 2 Equivalent digital value available in the dat
167. nterrupt can be generated when the compare 2 flag is set 130 235 ky Function Descriptions To perform the input capture only the ICAP2 pin can be used not the ICAP1 pin Take care that the counter is reset each time a valid edge occurs on ICAP1 pin and that the capture 1 flag can also generate interrupts if the input capture interrupt is enabled and the rim instruc tion has been used to clear the I bit When OPM is used the input capture1 register is dedicated to this mode Similarly output compare 2 cannot be used as level OLVL2 is dedicated to OPM By enabling the Forced compare mode while OPM mode is enabled the polarity of the OPM Output waveform may change Table 83 TIMERx_ICAP_Getvalue Function Name TIMERx_ICAP_Getvalue Function Prototype Behaviour Description Unsigned int TIMERx_ICAP_Getvalue Timer_Icap ICAP 1 Returns the input capture1 or input capture 2 register val ue depending upon the input parameter passed This function should be called twice in order to get both input capture1 and input capture2 register values Input Parameters TIMER ICAP I where can be 1 or 2 I 1 Input capture 1 register value is returned l 2 Input capture 2 register value is returned Output Parameters Input capture 1 or Input capture 2 register value The re turned value can be in the range 0x0000 to OxFFFF Required Preconditions ICF1 and or ICF2 1 You have to c
168. o 0x00 0x40 0x50 0x60 0x70 Ox7f Table 142 WDG_ComputeTimeout Function Name WDG_ComputeTimeout Void WDG_ComputeTimeout unsigned long WDG_Timeout Sets the value of Watchdog counter as per the selected Timeout and activates the watchdog Function Prototype Behaviour Description WDG_Timeout Input Parameter Required Watchdog Timeout This value must be entered in microseconds Output Parameter None You must define Fcpu and Fosc2 in ST7lib_config h cor rectly Functions called None Required Preconditions 1 The Watchdog is activated after this function and can not be disabled except by a reset 2 A Reset is generated after a time approximately equal to WDG Timeout If the Watchdog counter is not changed in between 3 For window watchdog a reset is generated also if this routine is called when the Watchdog counter value is greater than the Window register value 1 Postconditions 1 This condition is valid only for Window Watchdog Notes This function will give the approximate Timeout For more accurate results you must do the calculations as per the formulas given in the datasheet and call the previous function for loading counter value If the selected Watchdog Timeout is not possible you will get the next possible value To prevent the Watchdog reset this routine must be called when the Watchdog counter val ue 1 is greater than Ox3F 2 and lower than the W
169. oid SCIx Compute Baudrate unsigned int BaudRate Tx unsigned int BaudRate Rx Selects Transmitter Receiver baudrate for the SCI without extended prescaler BaudRate Tx You can select any possible baudrate for transmission BaudRate Rx You can select any possible baudrate for reception Output Parameter None Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 1 SCIx_Init must have been called Required Preconditions i i 2 fcpu must have been defined in ST7lib Config h Functions called None Postconditions None Note This function takes a large ROM area as calculations for TR RR and PR are done inside the function However you can choose to pass the baudrate directly If the selected baudrate speed is not possible the closest possible value will be used If there is no common prescalar factor for receiver and transmitter baudrates then you will get the nearest possible receiver baudrate at the prescalar division factor selected for the transmitter In half Duplex mode you can pass the same transmitter and receiver baudrates to get the exact Tx Rx baudrate whichever mode you are using 3 35 235 Function Descriptions Table 8 SCIx Select Baudrate Function Name Function Prototype SCIx Select Baudrate Void SCIx Select Baudrate SCI Baudrate Type Baudrate Prescaler Behaviour Description Selects Transmit Receive baudr
170. on is called in this way for hiware compiler when small memory model is used while EEPROM_Programming EEPROM_PROG_COMPLETE Waiting till all data bytes programmed from latch to EEPROM cells E EPROM Read Temp2 NoofBytes amp ptr_address Reads data from EEPROM address 1000h and stores it in buffer Temp2 EEPROM Read Temp2 5 unsigned char far 0x1000 Read function is called in this way for hiware compiler when small memory model is used for i 0 i lt 5 i Comparison of written data and data read if Templ i Temp2 i Mismatch between written data and data read while 1 Program Stop 218 235 STA Function Descriptions 9 1 16 1 0 The following are the functions related to Input Output ports Function Name IO Init Function Prototype Behaviour Description Void IO Init void Initialization of IO Loads IO registers with reset value 00h Input Parameters Output Parameters None None Reguired Preconditions Functions called Selection of the right device in the file ST7lib config h None Postconditions See also None None Note The bits associated with unavailable pins must always keep their reset value Y 219 235 Function Descriptions Table 166 IO Input Function Name IO Input Void
171. on Descriptions 9 1 3 SPI Following are the functions related to SPI Function Name SPI Init Function Prototype Behaviour Description Input Parameter 1 3 Void SPI Init SPI Init Parameter1 Init Value1 SPI Init Parameter2 Init Value2 Initialization of the SPI By default the SPI is put in slave mode hardware selected baudrate Fcpu 8 the SPI pe ripheral is not connected to the external pins SPE 0 al ternate function of SPI output enabled SOD 0 and interrupts are disabled You can change the default config uration by selecting input parameters given below You can pass one or more parameters by OR ing them SPI DEFAULT Reset Value SPI ENABLE Enables the serial peripheral output SPI alternate func tions connected to pins SPI ENABLE IT Enables the Interrupt Selects the clock baudrate by selecting one of the below parameters For SPI BAUDRATE 4 Clock baudrate is Fcpu 4 For SPI BAUDRATE 8 Clock baudrate is Fcpu 8 De fault baudrate value For SPI BAUDRATE 16 Clock baudrate is Fcpu 16 For SPI BAUDRATE 32 Clock baudrate is Fcpu 32 For SPI BAUDRATE 64 Clock baudrate is Fcpu 64 For SPI BAUDRATE 128 Clock baudrate is Fcpu 128 Selects the clock polarity and clock phase by selecting one of the below parameters SPI CLK PP 0 For CPOL 0 CPHA 0 Default clock polarity and phase SPI CLK PP 1 For CPOL 0 CPHA 1 SPI CLK PP 2 For CPOL 1 CPHA 0 SPI CLK PP 3 For
172. on is ignored The data reception will stop if any error occurs during reception 3 71 235 Function Descriptions Table 41 SPI IsReceptionCompleted Function Name Function Prototype SPI IsReceptionCompleted SPI RxErrCode t SPI IsReceptionCompleted void Behaviour Description Input Parameters For reception of a set of data in SPI Interrupt driven mode this function checks for the completion of the recep tion or the occurrence of an error and returns the reception status For reception of single byte of data in either SPI Polling or SPI Interrupt driven mode it checks if a data byte has been received and is ready for processing It returns SPI RX DATA EMPTY until the data byte is received and returns the reception status afterwards None Output Parameters Required Preconditions SPI_RX_MODF If master mode fault occurs SPI_RX_OVR If overrun condition occurs SPI_RECEIVE_OK If the reception is completed without any error SPI RX BUFFER ONGOING If the buffer is not full SPI RX STRING ONGOING If the complete string is not received in the user buffer SPI RX DATA EMPTY If no data byte is received None Functions called Postconditions None 1 For single byte reception if the byte is received then SPI GetByte can be called after this function 2 SPI Clear Flags can be called to clear the error and status flags if reguired See also None 1 These
173. on will over program the memory If a programming cycle is interrupted by software or a reset ac tion the integrity of the data in memory is not guaranteed Reading the EEPROM memory is not possible when the data writing is in progress Y 217 235 Function Descriptions Example The following C program shows the uses of the EEPROM functions for the LiteO device Program Description This program writes 5 data bytes in EEPROM memory from one user buffer Temp1 Then data bytes are read from the same EEPROM memory and stored in another buffer Temp2 The written data and data read from the two buffers are then compared Program Start include ST71ib_Config h File for user to select device as lite0 ifdef _HIWARE_ unsigned char ptr_address 0x1000 endif ifdef COSMIC near unsigned char ptr address 0x1000 endif void main void void main void int i unsigned char NoofBytes 5 unsigned char Temp1 5 0x55 0xAA 0x7F 0x18 0x4C unsigned char Temp2 5 0x00 0x00 0x00 0x00 0x00 efar unsigned char ptr write far unsigned char ptr read ptr read sptr address ptr write sptr address EEPROM Init All EEPROM registers initialised to reset value EEPROM Write Temp1 NoofBytes amp ptr_address Data written from buffer Templ to EEPROM memory address 1000h EEPROM Write Temp1 5 unsigned char far 0x1000 Write functi
174. on will stop as soon as an error occurs Y 47 235 Function Descriptions Table 23 SCIx GetString Function Name Function Prototype SCIx_GetString Void SCIx GetString unsigned char PtrToString Behaviour Description Input Parameters Output Parameters Reception of data string starts through interrupt driven mode PtrToString Start address of the location where string is to be placed None Reguired Preconditions 1 SCIx Mode must have been called 2 You must enable the interrupt due to Receive Data Ready flag 3 You must select the Interrupt driven reception mode in ST7lib_Config h 4 SCIx_IT_Function must have been called inside the SCI interrupt subroutine Functions called Postconditions See also None You must call SCIx IsReceptionCompleted after this func tion to check the reception status SCIx GetString Polling mode Note This function is only for Interrupt driven mode Caution Take care not to access the user buffer until reception is completed Any data received before calling this function is ignored The data reception will stop as soon as an error occurs 48 235 3 Function Descriptions Table 24 SCIx IsReceptionCompleted Function Name SCIx IsReceptionCompleted Function Prototype SCI RxError t SCIx IsReceptionCompleted void In Interrupt driven mode this function checks for the completion of reception of a set of data
175. one Note You can call this function whenever the error flags are reguired to be cleared forcibly Caution Do not call this function if a reception reguest is ongoing as it will corrupt the recep tion status by clearing all the flags and you will not receive any error status 96 235 x Function Descriptions Table 60 I2C_ ACK Function Name Function Prototype I2C ACK Void I2C ACK I2C ACK Param ACK Value Behaviour Description Input Parameters Enables or disables acknowledge bit depending on the in put I2C ACK ENABLE Enables the acknowledge bit I2C ACK DISABLE Disables the acknowledge bit Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Table 61 12C_Peripheral_Disable Function Name 12C_Peripheral_Disable Function Prototype Behaviour Description Void 12C_Peripheral_Disable void Disables the peripheral Input Parameters None Output Parameters None Required Preconditions None Functions called None Postconditions See also You must call 12C_Init after this to enable peripheral None Note When the peripheral is disabled all 12C register bits except the stop bit and speed se lection bits are cleared 3 97 235 Function Descriptions Table 62 12C_Generate_Stop Function Name Function Prototype I2C Generate Stop Voidl2C Generate Stop void Behaviour Descript
176. onfigured in Input Interrupt mode None Postconditions See also The external interrupt will be disabled and alternate func tion in the pin can be enabled ITC_Configurelnterrupt 1 This function is available only in ST72F62 8 ST72F63B Caution You must refer to the datasheet of the device while selecting the interrupt Pin If you select a wrong interrupt pin then the specified interrupt will not be disabled Table 153 ITC_Revert_Sensitivity Function Name Function Prototype ITC_Revert_Sensitivity Void ITC_Revert_Sensitivity ITC IT IT Behaviour Description Reverts the sensitivity of the ElO or El2 interrupt depend ing upon the input parameter See table below Input Parameters IT_EI0 Reverts the sensitivity of External interrupto IT_El2 Reverts the sensitivity of External interrupt2 Output Parameters None Required Preconditions None Functions called None Postconditions None See also None Note This function is for ST72F21 ST72325 and ST7232A devices ky 203 235 Function Descriptions Previous Sensitivity Falling edge and low level Reverted Sensitivity Rising edge only Falling edge only Rising edge and high level Falling edge only Rising edge only Rising and falling edge Table 154 ITC EnableTLI Function Name Rising and falling edge ITC EnableTLI Function Prototype Behaviour Description Void ITC EnableTLI void
177. or condition Caution You can lose the control if I2C is disabled while using this function ky 113 235 Function Descriptions Table 71 12Cs GetBuffer 12C Interrupt driver Function Name Function Prototype 12Cs_GetBuffer Void I2Cs GetBuffer unsigned char PtrToBuffer un signed char MaxSize Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts reception of data from the user defined area by ini tializing the reception buffer in the I2C ITDRV WITHOUTBUF RX mode PtrToBuffer Start address of the user buffer MaxSize Size of the buffer None Reguired Preconditions Functions called 1 You must define 12C_ITDRV_WITHOUTBUF_RX mode in ST7lib_config h 2 12Cs_RX_MODE must be detected through I2Cs GetCommMode before calling this function The status of the reception should be checked through 12Cs_IsReceptionCompleted function Postconditions See also None I2Cs GetBuffer I2C Polling mode Note The above function is only forI2C ITDRV WITHOUTBUF RX mode Table 72 12Cs_GetByte Function Name Function Prototype I2Cs GetByte Unsigned char I2Cs_GetByte void Behaviour Description Input Parameters Returns received byte from I2C bus None Output Parameters Reguired Preconditions Received data byte I2Cs GetCommMode must have been called before re ceiving first byte or reception of previous data has taken succe
178. overflow interrupt TBU SetPrescCount8 TBU Prescvalue 256 Counter Value8 Generates Interrupt after lms counter TBU_ReadCounter Reads the value of counter E eo ee A See EN ie ee See as ee aa a ee E ee o o iS SS ee ee For Cascade Mode a ee he C E ji L l S E o o ESS S E E E OE A S E else ifdef TBU Cascade Selects Cascade mode TBU Init TBU IT ENABLE TBU ART CASCADE Enable interrupt and select Cascade mode TBU SetPrescCount16 TBU CasPrescvalue 128 Counter _Valuel6 Generate an interrupt after 1 second endif endif TBU Enable Enable the TBU counter while 1 BERR ELAARAREL ENRERE K o KK k LEAT AH COLT UD E Subroutine eR KKK KKK KKK KK KKK KKK ifdef _HIWARE_ test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved telse ifdef _COSMIC_ Test for Cosmic Compiler interrupt Cosmic interrupt handling else terror Unsupported Compiler Compiler Defines not found endif endif void TBU_IT_Routine void TBU ClearOverflow Clears the Overflow flag 3 191 235 Function Descriptions 9 1 12 WDG Table 140 WDG_Refresh Function Name WDG_Refresh Function Prototype Behaviour Description Void WDG_Refresh unsigned char Counter_Data Loads the value of Watchdog counter and activates the Watchdog Input Parameter Output Parameter Counter_Data Value which is loaded in t
179. ow Function name Function prototype Behaviour Description Input Parameters Output Parameters Required preconditions Functions called Post conditions See also Note Caution Code example 3 Peripheral name and main functionality covered Prototype declaration Brief explanation of how the functions are executed Description of the parameters to be passed Value returned by the function Specific reguirements to run the function Library Functions called Function reguired to call immediately after this function Related functions for user reference Important points that you must take into consideration Important points to be considered to avoid any failures Example to show the proper way to use the library func tions 27 235 Release Information 8 RELEASE INFORMATION This release supports the following peripherals and devices 8 1 PERIPHERALS ADC 8 bit and 10bit The on chip Analog to Digital Converter ADC peripheral is a 10 bit successive approximation converter with internal sample and hold circuitry SCI with without extended Baud Rate Pre scalar The Serial Communications Interface SCI offers a flexible means of full duplex data exchange with external equipment requiring an industry standard NRZ asynchronous serial data format SPI The Serial Peripheral Interface SPI allows fullduplex synchronous serial communi cation with external devices 12C single multi master The Inter
180. p Temp2 I2C_RX_DATA_EMPTY Temp2 12C_IsReceptionCompleted Waits for data byte reception if User Timeout Function switch Temp2 case I2C RX ARLO case I2C RX BERR Rx Data I2C GetByte User Function break case I2C DATA RX OK 3 Function Descriptions Rx_Data 12C_GetByte break default None of the above condition is true User Function break Reception of set of data in the user buffer I2C GetBuffer Buff Test unsigned char 10 Any data received before calling this function is ignored Here user can perform other tasks or operations except reception till the time reception is complete after which user can perform reception again Timeoutcount 0 Temp2 12C_IsReceptionCompleted while User Timeout Function amp amp Temp2 I2C_RX_BUFFER_ONGOING Temp2 12C_IsReceptionCompleted To be sure that the communication by this point has been completed if User Timeout Function switch Temp1 case I2C RX BERR case I2C RX BUFFER ONGOING User Function Error Management break case I2C DATA RX OK Reception successful break default If none of the above condition is true break endif SSE Em SSE l A AAA EIA ROUTINE NAME I2C User IT Routine INPUT None OUTPUT None DESCRIPTION Control comes into this routine when an interrupt is g
181. peed SCI PR X X 1 3 4 13 SCI_TR_Y Y 1 2 4 8 16 32 64 128 SCI_RR_Z Z 1 2 4 8 16 32 64 128 EPTR Select any value from O to 255 EPRR Select any value of EPRR from 0 to 255 Output Parameter None Input Parameter 1 Input Parameter 2 Input Parameter 3 1 SCIx_Init must have been called Required Preconditions 2 You have to specify the PR RR and TR values for the desired baudrate Functions called None Postconditions Refer to the table below Transmitter RECRIVET SCI_PR_X 2 E EPTR EPRR baudrate baudrate speed Speed SCI_PR_13 F 1 1 38400 38400 SCI PR 13 SCI PR 13 E SCI_PR_13 SCI_PR_13 SCI_PR_13 3 37 235 Function Descriptions Table 10 SCIx IT Enable Function Name Function Prototype SCIx IT Enable Void SCIx IT Enable SCI IT Type SCI IT Param Behaviour Description Input Parameters Output Parameter Selects SCI interrupts SCI IDLE LINE Enable interrupt due to idle frame reception SCI RECEIVE OVERRUN Enable interrupt due to data reception or overrun error SCI TRANSMIT REGISTER READY Enable interrupt when transmit data register is ready to load SCI FRAME TRANSMITTED Enable Interrupt due to Transmission completetion SCI PARITY ERROR Enable Interrupt due to Parity Error None Reguired Preconditions 1 SCIx_ComputeBaudrate or SCIx SelectBaudrate must have been called 2 You should reset the interrupt mask with Enablelnt
182. put capture register value Required Preconditions LART_ICAPMode must have been called This function should be called only after Input Capture flag is set flag is checked either by polling or by enabling Input capture in terrupt Functions called Postconditions None None See also LART_ICAPMode Note This function is available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI de vices 3 179 235 Function Descriptions Table 125 LART_ConfigureBREAK Function Name Function Prototype LART_ConfigureBREAK Void LART_ConfigureBREAK Lart_BREAKPinState BREAKPinState Lart_BREAK_PWMPattern PWMPat tern Behaviour Description Input Parameter This function enables disables the BREAK pin function and loads the PWM bit pattern to be generated in BREAK state BREAKPinState LART BREAK ENABLE Enables BREAK Pin Break condition will be generated by applying low signal to BREAK LART BREAK DISABLE Disables BREAK Pin Break condition generated by soft ware PWMPattern Pattern to be generated on PWM pins Following parame ters are passed as input These parameters can be logi cally ORed to pass multiple parameters LART_BREAK_PWMO_HIGH LART BREAK PWMO LOW LART BREAK PWM1 HIGH LART BREAK PWM1 LOW LART BREAK PWM2 HIGH LART BREAK PWM2 LOW LART BREAK PWM3 HIGH LART BREAK PWM3 LOW Output Parameters None Reguired Preconditions None Functions called None Post
183. r NO OF TX HANDLES and the value s stored inside the table is are the same as defined by the parameter TX MSGx EXTID in the file user h It stores the values into the same format as of MIDR2 amp MIDR3 registers 4 tx_dlc This table stores the length for the message s to be transmitted The length of the table is the same as defined by the parameter NO OF TX HANDLES and the value s stored inside the table is are the same as defined by the parameter TX MSGx DLC in the file user h 5 tx_data_ptr This pointer table stores the address of transmit buffer s MSGx Tx buffer The length of the table is the same as defined by the parameter NO OF TX HANDLES in the file user h 6 MSGx Rx Buffer This declares the buffer for the MSGx to be received The length of the buffer is the same as defined by the parameter RX MSGx DLC in the file user h Number of such buffers to be declared is the same as defined by the parameter NO OF RX HANDLES in the file user h 24 235 STA How to use the library 7 rx_stdid This declares the memory for storing the standard id part of the message to be re ceived The length of the table is the same as defined by the parameter NO_OF_RX_HANDLES in the file user h 8 rx_extid This declares the memory for storing the extended id part ofthe message to be re ceived The length of the table is the same as defined by the parameter NO_OF_RX_HANDLES in the file user h 9 rx dlc This table stores the leng
184. r example ST7232x EVAL ST7 STICK ST in circuit communication kits ICC socket boards these complement any tool that has ICC programming capabilities like ST7 STICK INDART R Link DVP EMU etc Third party emulators from Hitex or SYSTEM Engineering Programming Board EPB or Gang Programmer 3 3 TECHNICAL LITERATURE As well as reading the ST7 device datasheet you should also read the following documents before using the library All the documents and the device datasheets are available on the ST website and on the MCU CD ROM ST7 Software library user manual Application note AN978 Key features of the STVD7 ST7 Visual debug package Application note AN989 Getting started with the ST7 Hiware C Toolchain Application note AN983 Key features of the Cosmic ST7 C Compiler package Application note AN1064 Writing Optimized Hiware C Language for ST7 Application note AN1938 Visual Develop for ST7 Cosmic C Toolset Users Application note AN1939 Visual Develop for ST7 Metrowerks C Toolset Users 8 235 3 Getting Started with Tools 3 4 HOW TO INSTALL THE LIBRARY The library is supplied in a zip package Extraction of this zip file will give the setup file ST7LibxSetup exe where x represents the latest numeric version of the library Click on the setup file to install the library on the host system 3 9 235 Library Structure 4 LIBRARY STRUCTURE 4 1 ST7_LIBX Location Root directory
185. r transmission and reception 7 bit Tx 7 bit master transmitter 7 bit Rx 7 bit master receiver You can select any one pair of the following communication modes For Polling Mode I2C POLLING TX For Transmission mode I2C POLLING RX For Reception mode For Interrupt Driven Mode I2C ITDRV WITHOUTBUF TX For Transmission mode I2C ITDRV WITHOUTBUF RX For Reception mode You can use a time out function to handle the fault in which the control will get stuck inside a loop This function should have the Boolean return i e it should return TRUE if the expected wait Time is not elapsed and FALSE if it is elapsed ISA 117 235 Function Descriptions Software Control Wait loop User defined time out function The following variables are declared in main h file main h ifndef MAIN define MAIN void I2Cs User IT Routine void void main void BOOL Time Out void Prototypes of user function void User_Function void unsigned int count 0 endif mmm nese e ee eee anaes ease mmmm Program Start This example code explains the usage of I2C slave in the transmitter and receiver mode First the slave is configured as a transmitter and it transmits 10 bytes of data from the user buffer Then it is configuredasa receiver and it reads the same 10 bytes of data and they are compared
186. ransmission is complete after which user can perform transmission again Templ SPI_IsTransmitCompleted while Templ SPI_TX_BUFFER_ONGOING amp amp Templ SPI_TX_STRING_ONGOING Wait for transmission completion Templ SPI_IsTransmitCompleted switch Temp1 case SPI TX MODF SPI TX WCOL case SPI TX MODF case SPI TX WCOL User Function Error Management break case SPI TRANSMIT OK Transmission is successful break default If none of the above condition is met User Function break Transmission of 10 data bytes from user buffer User pointer is copied to the global pointer SPI PutBuffer Buff NbofBytes put Here user can perform other tasks or operations except transmission till the time transmission is complete after which user can perform transmission again Templ SPI IsTransmitCompleted while User Timeout Function 8 s Templ SPI TX BUFFER ONGOING Templ SPI_IsTransmitCompleted To be sure that the communication by this point has been completed if User_Timeout_Function switch Temp1 case SPI_TX_MODF SPI TX WCOL case SPI TX MODF case SPI TX WCOL 77 235 Function Descriptions else User Function Error Management break case SPI TRANSMIT OK Transmission successful break default If none of the above condition is met User Function
187. receiver 2 You can directly call this function to get the mode of communication after getting Address matched condition irrespective of whether it is 7 bit or 10 bit address detection 3 If you are calling this function in a loop for detecting the mode of communication then control will not come out of this loop till the first BTF condition occurs So if BTF is never set then the program will lose control in the above loop In this case you can use note 1 to tackle this problem to detect the error condition inside the loop 3 109 235 Function Descriptions Table 66 I2Cs_PutBuffer Function Name Function Prototype 12Cs_PutBuffer 12Cs_ErrCode_t12Cs_PutBuffer unsigned char PtrTo Buffer unsigned char MaxSize Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Transmits data buffer from the user defined area for I2C POLLING TX mode The data transmission will dis continue if any error occurs during transmission and the error status will be returned PtrToBuffer Start address of the user buffer MaxSize The maximum no of bytes to be transmitted I2Cs BERR An bus error has occurred 12Cs_ADDRESS_DETECTED If the device address is matched I2Cs GENERAL CALL If the general call is detected I2Cs TX DATA OK If there is no error in data transmission and stop is detect ed correctly I2Cs OVERFLOW TX If transmission has taken place correctly but the some byte transmitt
188. rectly 2 You must define SPI Polling mode in ST7lib config h Functions called None See also SPI GetBuffer SPI Interrupt driven mode Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Required Preconditions Note The above function is only for SPI Polling mode Caution The application can lose control if the SPI is disabled while using this function in poll ing mode 3 69 235 Function Descriptions Table 39 SPI_GetString Function Name SPI_GetString Function Prototype Void SPI GetString unsigned char PtrToString Starts reception of a data string in SPI Interrupt driven Behaviour Description mode in the interrupt service routine and stores it in a user defined area PtrToString Input Parameters Start address of the location where the string is to be placed Output Parameters None 1 The SPI should be configured correctly 2 You must define SPI Interrupt driven reception mode in ST7lib_config h 3 You must enable interrupts for this mode 4 For SPI Interrupt driven mode SPI IT Function must have been called in the Interrupt service routine Required Preconditions Functions called None You must call SPI IsReceptionCompleted after this to check the reception status SPI IsReceptionCompleted SPI GetString SPI Polling mode Postconditions See also Note The above function is only for SPI Inter
189. rectory structure main c st7lib_config h st72xx_periph h STVD7_2x STVD7_3x periph_mwerks stw periph_mweks stp interrupt_vector c vector c periph_csmc stw periph_csmc stp Config periph_mwerks wsp periph_csmc wsp Object st72xxx mak st72xxx mak periph map periph map st72xxx Ikf st72xxx prm periph elf periph abs vector xxx c default env periph o periph o main o main o periph_hr O periph_hr O periph st7 periph s19 vector_xxx 0 periph s19 5 1 SOURCES FOLDER Description Contains the ST7lib_config h the main application file and the peripheral source files needed to run the application 14 235 3 Example 5 2 WORKSPACE This folder contains configuration and workspace files for both STVD7 ver2 x and 3 x as per the directory structure shown in figure 2 Note 1 For ST72F561 demo and CAN peripheral winIDEA workspace is also available 2 For ST72325 and ST7232A demo STVD7_3X workspace is only available 5 2 1 STVD7_2x This folder contains relevant configuration files for ST7 Visual Debug ver 2 x Subdirectories Config Object Config Folder Contains the configuration files for both Metrowerks and Cosmic compilers metrowerks Contains the mapping file ST72xxx prm for all the hardware registers in the de vice the Make file ST72xxx mak for building the application and the default env file which defines all the useful paths names a
190. register values of SDA and SCL pins changes if user calls this function So you must take the port register values into account 98 235 Y Function Descriptions EXAMPLE The following C program shows the uses of the 12C functions Program Description This program runs the following sequence for multimaster I2C ST72F521 device for I2C Polling and 12C Interrupt driven communication modes 1 Transmits a single byte passed by the user and receives single byte of data in 7 bit ad dressing mode 2 Transmits and receives the10 bytes of data in 7 bit addressing mode The following modes are used for transmission and reception 7 bit Tx 7 bit master transmitter 7 bit Rx 7 bit master receiver You can select one pair of the following communication modes for transmission and reception respectively I2C POLLING TX For Transmission mode I2C POLLING RX For Reception mode I2C ITDRV WITHOUTBUF TX For Transmission mode I2C ITDRV WITHOUTBUF RX For Reception mode You can use a timeout function to handle the fault in which the control will get stuck inside a loop This function should have the Boolean return i e it should return TRUE if the expected wait Time is not elapsed and FALSE if it is elapsed Software Control Wait loop User defined time out function The following variables are declared in main h file main h ifndef MAIN define MAIN void main void void I2C User IT Routine void
191. responding flag is cleared when the TRUE is returned 3 155 235 Function Descriptions Table 106 LT_Clear_Flag Function Name LT_Clear_Flag Function Prototype Void LT_Clear_Flag Lt_Flag FLAG F Clears the status flag depending upon the input parameter Behaviour Description passed This function can be called more than once to clear more than one flag LT_FLAG_TBF clears the Timebase interrupt flag LT_FLAG_TB1F clears the Timebase1 interrupt flag LT_FLAG_TB2F clears the Timebase2 interrupt flag LT_FLAG_ICF clears the input capture flag LT_FLAG_WDGRF clears the watchdog reset status flag Input Parameters Output Parameters None Required Preconditions TBF 1 or TB1F 1 or TB2F 1 or ICF 1 or WOGRF 1 Functions called None Postconditions Selected status flag is cleared See also LT_Status _Flag 1 Defined for ST7FLITEO and ST7SUPERLITE 2 Defined for ST7FLITE1 2 3 and ST7FDALI 3 Defined for ST7FLITEO and ST7SUPERLITE Note After reset calling this function with the input parameter FLAG_ICF also initializes the input capture The input capture is inhibited if the ICF flag is set EXAMPLE The following C program example shows the use of the LT functions for the ST7FLiteO device Program description This program detects an event rising edge amp trailing edge at the LTIC pin and toggles a LED every 5 seconds Program start include ST7lib_config h select ST7FLITE
192. rogramming Notes The value of PtrToE2Buffer can be from 0x1000h to 0x107Fh for ST7FLite0 1 2 3 ST7SUPERLITE and ST7DALI device You have to type cast parameter PtrToE2Buffer to unsigned char in the function EEPROM Write as shown in example page 218 To avoid incorrect programming take care that all the bytes written between the two pro gramming seguences have the same high address only the four Least Significant Bits of the address can change Because of the ST7FLite0 1 2 3 ST7SUPERLITE and ST7DALI ZRAM and RAM size limi tation which is 64 bytes each you must take care while declaring the size of user buffer 216 235 x Function Descriptions Table 165 EEPROM_Programming Function Name Function Prototype EEPROM_Programming Prog_Status EEPROM_Programming void Behaviour Description Input Parameters Starts writing data bytes from EEPROM latches to EEP ROM cells and returns the programming status None Output Parameters EEPROM_PROG_COMPLETE If all data bytes are written from latch to EEPROM cells EEPROM_PROG_PROGRESS If programming cycle is in progress Required Preconditions Functions called EEPROM_Write must have been called None Postconditions See also This function can be looped until the programming cycle is complete EEPROM_Write Notes Care should be taken during programming cycle Writing to the same memory locati
193. rototype TIMER8_Clear_Flag Void TIMER8_Clear_Flag Timer8_Flag FLAG_F Behaviour Description Input Parameters Output Parameters Clears the status flag depending upon the input parameter passed This function can be called more than once to clear more than one flag TIMER8_FLAG_F where F can be ICF1 ICF2 OCF1 OCF2 or OVF F ICF1 Clears the Input Capture1 Flag F ICF2 Clears the Input Capture2 Flag F OCF1 Clears the output compare1 Flag F OCF2 Clears the output compare2 Flag F OVF Clears the timer overflow Flag None Required Preconditions Functions called ICF1 1 or ICF2 1 or OVF 1 or OCF1 1 or OCF2 1 None Postconditions See also Selected status flag is cleared TIMER8_IT_Routine TIMER8_Status_Flag 3 147 235 Function Descriptions EXAMPLE The following C program shows the use of the TIMER8 functions Program description It compares the output compare2 register value with the free running counter checks the oc currence of event leading edge at ICAP2 pin It generates PWM signal with 10KHz frequency and with 33 Duty cycle at the OCMP1 pin if Enable PWM is defined in main c or it gen erates the 0 1ms pulse at OCMP1 pin if _Enable_OPM_ is defined in main c Fcpu 8 MHz Program start tinclude st7li prototype dec void main void b config h laration i void TIMER8_IT_Routine void void main void File for user
194. rs during transmission The transmission status will be returned PtrToBuffer Start address of the user buffer NbOfBytes Number of data bytes to be transmitted SPI_TX_WCOL If write collision error occurs SPI_TX_MODF If master mode fault occurs SPI_TRANSMIT_OK If there is no error in transmission 1 SPI should be configured correctly Function Prototype Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Required Preconditions 2 You must define SPI Polling transmission mode in ST7lib_config h Functions called None See also SPI_PutBuffer SPI Interrupt driven mode Notes The above function is only for SPI Polling mode For transmission in software slave mode you must define SPI_SLAVE_CONFIG in ST7lib_config h Caution The application can lose control if the SPI is disabled while using this function in poll ing mode 3 63 235 Function Descriptions Table 33 SPI_PutString Function Name SPI PutString Function Prototype Void SPI PutString const unsigned char PtrToString Starts transmission of data string in the interrupt service Behaviour Description routine from the user defined area for SPI Interrupt driv en mode PtrToString Start address of the user string Output Parameters None 1 The SPI should be configured correctly Input Parameters 2 You must define SPI Interrupt driven mode in ST7lib_config h 3 Yo
195. rupt driven mode Caution Take care not to access the string until reception is complete Any data received before calling this function is ignored The data reception will stop if any error occurs during reception 3 70 235 Function Descriptions Table 40 SPI GetBuffer Function Name Function Prototype SPI GetBuffer Void SPI GetBuffer unsigned char PtrToBuffer un signed char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts reception of data in the interrupt service routine and stores it in user defined area for SPI Interrupt driven mode PtrToBuffer Start address of the user buffer NbOfBytes Number of bytes to be received None Required Preconditions Functions called 1 The SPI should be configured correctly 2 You must define the SPI Interrupt driven reception mode in ST7lib config h 3 You must enable interrupts for this mode 4 For SPI Interrupt driven mode SPI IT Function must have been called in the Interrupt service routine None Postconditions See also You must call SPI IsReceptionCompleted after this to check the reception status SPI IsReceptionCompleted SPI GetBuffer SPI Polling mode Note The above function is only for SPI Interrupt driven mode Caution Take care not to access the string until reception is complete Any data received before calling this functi
196. s mechanism can only be used with the I2C in half duplex mode To use this mode you must have selected the following define labels in the ST7lib config h file I2C POLLING TX For Transmission mode I2C POLLING RX For Reception mode Interrupt driven without communication buffer Data can be Transmitted Received both in single as well as continuous mode through the in terrupt driven mechanism In continuous mode the user data is directly read written from to the addresses passed by the user After each byte of data transfer an interrupt is acknowledged and the control goes to the interrupt subroutine The advantage of using interrupts rather than polling is that control does not stay in the function till the last data is Transmitted Received Here care should be taken not to read write the user buffer until the Transmission Reception completes To use this mode you must select the following define labels inside the ST7lib_config h file I2C ITDRV WITHOUTBUF TX For Transmission I2C ITDRV WITHOUTBUF RX For Reception Master Receiver Communication Methodology In Master receiver mode to close the communication the STOP bit must be set to generate a stop condition before reading the last byte from the DR register In order to generate the non acknowledge pulse after the last received data the ACK bit must be cleared just before reading the second last byte The following flowchart shows the management of the ACK and STOP bits when th
197. s part of the user manual contains the detailed description of all the functions for the CAN Library Note These functions are only available for the ST72F561 CAN Peripheral 9 2 1 1 Initialization Services Table 171 CanlnitPowerOn Function Name CanlnitPowerOn Function Prototype Input Parameters void CanlnitPowerOn void None Output Parameters Behaviour Description None This service initializes the CAN driver internal variables Indication and Confirmation flags are reset Tx Rx buffers are cleared Table 172 Canlnit Function Name Function Prototype Canlnit void Canlnit CanlnitHandle lt initObject gt Input Parameters initObject Selected Initialization Mode For example If the value passed is 0 the Can Controller will be initialized with the values of init table 0 Output Parameters Behaviour Description Reguired Preconditions None This service initializes the CAN Controller regis ters with the values stored in the init table corre sponding to the lt initObject gt Pending transmit reguests within the CAN controller are deleted Receive FIFO is released The function shall be called after CanlnitPow erOn and before any other services of the driv er 3 227 235 Function Descriptions 9 2 1 2 Transmit Services Table 173 CanTransmit Function Name Function Prototype CanTransmit canuint8 CanTransmit CanTransmitHa
198. s per the device package define IO 521 80PIN Select this for an 80 pin package for ST72F521 device in ST7lib_config h file define IO 62 42PIN Select this for a 42 pin package for ST72F62 device in ST7lib_config h file define IO 62 32PIN Select this for a 32 pin package for ST72F62 device in ST7lib_config h file If you are using other device packages you must comment out these declarations in ST7lib_config h file 6 4 MEMORY MODELS Limitation in Cosmic you are not allowed to use the same function in both the main program and interrupt subroutine This will give the error of Reentrant function in all memory models ex cept mods and modsl 6 5 PORTING APPLICATIONS FROM LIBRARY VERSION 1 0 Applications can be ported easily from ST7 Library Version 1 0 to ST7 Library Version 2 0 by making the following changes Change the configuration files st7lib_config h default env mak prm and Ikf Add device reg o in compile list and link list in mak prm and Ikf files Remove inclusion of periph hr h files from main to access device registers directly Replace use of TIMERA TIMERB macros with USE TIMERA USE TIMERB Replace ITC EXT IT Sensitivity with ITC Configurelnterrupt Refer to the Release Notes for the list of changes in new version 26 235 3 Presentation of library functions 7 PRESENTATION OF LIBRARY FUNCTIONS 7 1 LIBRARY REFERENCES Functions are described in the format given bel
199. s service puts the controller into the sleep mode This reduces the power consumption of the CAN controller The service enables the autowakeup mode of the CAN controller so that CAN controller automatically performs the wake Output Parameters up sequence on detection of CAN bus activity You can wakeup the CAN controller using the CanWakeUp service If the sleep mode is en tered the service returns KCANOK Sleep mode is not entered if any message transmission is on going during call of this service Then the service returns KCANFAILED This service shall not be called while Tx Rx is in progress Behaviour Description Reguired Preconditions Table 178 CanWakeup Function Name CanWakeup Function Prototype canuint8 CanWakeup void Input Parameters None Output Parameters KCANOK Sleep Mode left This service puts the CAN controller into the nor mal operating mode Behaviour Description 230 235 3 Function Descriptions 9 2 1 4 Status Information Service Table 179 CanGetStatus Function Name Function Prototype CanGetStatus canuint8 CanGetStatus void Input Parameters Output Parameters None KCANHWISSLEEP CAN controller is in sleep mode KCANHWISBUSOFF CAN controller entered BusOff state KCANHWISPASSIVE Error Passive limit has been reached KCANHWISWARNING Error Warning limit has been reached Behaviour Description 9 2 1 5 Transmit Recei
200. selected Y 2 Forced compare is selected OCR VALUE You can select this value from 0x00 to OxFC TIMER8 OUTPUT F A low level is reflected at the output compare pin after suc cessful comparison TIMER8 OUTPUT R A high level is reflected at the output compare pin after suc cessful comparison Output Parameters None Required Preconditions Timer correctly initialized Functions called None Postconditions Timer8 starts functioning in either of the above selected modes and the compare flag is set whenever the compare occurs See also None Note When the Forced compare mode is selected the input parameter 2 will not affect the output waveform and hence you can pass any value between 0x00 to OxFC 3 139 235 Function Descriptions Table 90 TIMER8_ICAP_Mode Function Name Function Prototype TIMER8_ICAP_Mode Void TIMER8 ICAP Mode Timer8 Icap ICAP_l Timer8 Edge EDGE SELECT Y Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameter Configures the timer8 to Input capture mode It determines the type of level transition occurred on input capture pins This function should be called twice in order to use both ICAP1 8 ICAP2 TIMER8 ICAP I where can be 1 or 2 1 Input capture 1 is selected 2 Input capture 2 is selected TIMER8 EDGE Y where Y can be 0 or 1 Y 0 Capture occurs at falling edge Y 1 Capture occurs at the rising edge
201. sets counter clock f TIMER LART COUNTER CLK FCPU sets counter clock fopy LART OVF IT ENABLE enables overflow interrupt LART OCMP IT ENABLE enables compare interrupt LART DEFAULT sets default configuration 3 Output Parameters None Reguired Preconditions None Functions called None Postconditions LART is configured as desired See also None 171 235 Function Descriptions Table 116 LART_Disable Function Name Function Prototype LART_Disable Void LART_Disable Lart_Disable_Param DValue Behaviour Description Input Parameter Output Parameters Disables overflow interrupt or compare interrupt or makes counter clock OFF or all ofthese depending upon the input parameter passed More than one input parameter can be passed by logically ORing them together LART_OVF_IT_DISABLE disables overflow interrupt LART_OCMP_IT_DISABLE disables compare interrupt LART_COUNTER_CLK_OFF counter clock OFF LART_PWM_DISABLE disables PWMO output LART_PWMO_DISABLE disables PWMO output LART_PWM1_DISABLE disables PWM1 output LART_PWM2_DISABLE disables PWM2 output LART_PWM3_DISABLE disables PWM3 output LART ICAP IT DISABLE disables Input Capture interrupt LART CTR2 DISABLE disables counter 2 uses counter 1 only LART OVF2 IT DISABLE 2 disables counter 2 overflow interrupt LART LONG ICAP DISABLE disables long input capture mode None Reguired Preconditions Functions
202. should be called multiple times Table 119 LART_OCMP_Mode Function Name LART_OCMP_Mode Function Prototype Void LART_OCMP_Mode unsigned int Dutycycle_Data Puts timer in Output Compare mode This mode disables PWM output Behaviour Description P This function is used for ST7FLite0 only for other devices LART_ConfigureOCMP should be used Dutycycle Data Input Parameter Data to be loaded in Duty cycle register 0x000 to OxFFF which will be compared with upcounter Output Parameters None a de LART_Init must have been called to select the counter Required Preconditions clock Functions called None When the upcounter value reaches the Dutycycle_Data Postconditions the CMPFxflag is set and an interrupt is generated if com pare interrupt is enabled See also LART nit Notes This function can be used only with the ST7FLiteO device This function is added for backward compatibility with previous library For new develop ments LART_ConfigurePWM should be used with LART_OCMPO as the first parameter 3 175 235 Function Descriptions Table 120 LART_ConfigureOCMP Function Name Function Prototype LART_ConfigureOCMP Void LART_ConfigureOCMP Lart_OCMPChannel OCM PChannel unsigned int Dutycycle_Data Behaviour Description Input Parameter 1 Puts timer in Output Compare mode This mode disables PWM output OCMPChannel LART_OCMPO OCMPO is configured LART OCMP1 OC
203. smission Interrupt enable when RDR register is ready to read SCI IT Enable unsigned char SCI RECEIVE OVERRUN SCI Mode SCI RX ENABLE Err SCI IsReceptionCompleted Jwhile User Timeout Function amp amp Err SCI RX DATA EMPTY Wait for the completion of current data byte reception if User Timeout Function if Err SCI RECEIVE OK Reception OK Nop Rx_Data SCI_GetByte Nop else if unsigned char Err amp SCI NOISE ERR Userfunction if unsigned char Err amp SCI_OVERRUN_ERR 56 235 3 Function Descriptions 3 Userfunction E ps po if unsigned char Err amp SCI_FRAMING_1 Userfunction if unsigned char Err amp SCI_PARITY_ERR Userfunction Rx_Data SCI_GetByte User will receive the corrupted data else while 1 Transmitter or Receiver having problem tars tt a a Buffer Reception SCI_GetBuffer Buff_Rcv unsigned char 19 Any data received before calling this function is ignored Here user can perform other tasks or operations except reception till the time the function SCI_IsReceptionCompleted returns RECEIVE_OK after which user can perform reception again do Err SCI_IsReceptionCompleted while Err SCI_BUFFER_ONGOING To be sure that the communication by this point has been complet
204. ssfully which should be detected through I2Cs IsReceptionCompleted Functions called Postconditions None None See also 114 235 I2Cs PutByte Y Function Descriptions Table 73 12Cs IsReceptionCompleted Function Name I2Cs IsReceptionCompleted Function Prototype I2Cs ErrCode t12Cs IsReceptionCompleted void Returns the current status of 12C in reception mode for Behaviour Description Single Byte Polling and Interrupt both and Interrupt mode Buffer I2C communication Input Parameters None Common 12Cs_BERR If bus error is detected I2Cs ADDRESS DETECTED If the start condition is detected I2Cs GENERAL CALL If general call is detected I2Cs EMPTY The first byte has not received yet I2Cs DEFAULT STATUS No Communication event has occurred after receiving first byte Byte Specific I2Cs RX DATA OK Reception of the current byte has taken place successfully I2Cs STOP DETECTED If the stop condition is detected Output Parameters BufferSpecific 12Cs_BUFF_RX_ONGOING If the reception is ongoing successfully I2Cs RX DATA OK Reception has taken place successfully and stop is detect ed correctly I2Cs OVERFLOW RX Reception has taken place successfully and stop is detect ed correctly But overflow condition has occurred Required Preconditions None Functions called None Postconditions None See also I2Cs IsTransmitCompleted Notes The above function is for
205. t Input Parameter 2 Input Parameter 3 Selects port pin number Here you can select more than one pin number by OR ing them IO PIN W W 0to 7 Selects the data to be written in the port pin IO DATA HIGH Writes logic high in port pin IO DATA LOW Writes logic low in port pin IO DATA TOGGLE Toggles port pin Output Parameters Required Preconditions None To write data in output mode IO Output must have been called Functions called None Postconditions None See also None Notes When the I O port is in output configuration and associated alternate function is enabled as an input the alternate function reads the pin status given by the port DR register content This function reads DR register performs the bit operations and writes back DR This could give different results in some situations to avoid this use O_ByteWrite with shadow register variables 3 223 235 Function Descriptions EXAMPLE The following C program shows the use of the I O functions Program Description This program written for the ST72F521 device configures all Port D pins in push pull output mode The D5 and D7 port pins are put into logic high state The port register is read and the data is compared with the written data If there is any mismatch between the data read and data written the control goes into a while loop It then configures Port C C3 8 C4 in floating input mode
206. t TIMER FCPU 8 Timer Clock to Fcpu 8 and reset counter EnableInterrupts Clear I bit in CC reg Timer compares 0x2050 with free running counter TIMERA OCMP Mode TIMER OCMP 2 0O0CR VALUE TIMER OUTPUT R while TIMERA Status Flag TIMER FLAG OCF2 TRUE TIMERA Clear Flag TIMER FLAG OCF2 Clear output compare2 flag TIMERA IT Enable TIMER ICAP IT ENABLE Enable capture interrupt TIMERA ICAP Mode TIMER ICAP 2 TIMER EDGE 1 Detect rising edge at ICAP2 pin Run TIMERA in PWM mode if Enable PWM is defined ifdef Enable PWM Generate PWM TIMERA_PWM_Mode TIMER_OUTPUT1_F TIMER_OUTPUT2_R unsigned int 0x001C unsigned int 0x005F endif Run TIMERA in OPMmode if _Enable_OPM_is defined E ifdef _Enable_OPM_ TIMERA_Clear_Flag TIMER_FLAG_ICF1 Clear Input capturel Flag TIMERA Mode Disable TIMER MODE 5 Disable PWM TIMERA OPM Mode TIMER EDGE 1 TIMER OUTPUT1 F TIMER OUTPUT2 R unsigned int 0x1383 endif 5ms pulse while 1 For testing only Program end A E A cee eee tet Soe ete eS A ee See SSeS ee ees ROUTINE NAME TIMERA_IT_Routine INPUT None OUTPUT None S72 135 235 Functio n Descriptions DESCRIPTION Interrupt service routine COMMENTS This gets automatically executed when any of the timer interrupt is enabled If the same functions are called in the main Tree and the interrupt
207. t transmission till the time transmission is complete after which user can perform transmission again Timeoutcount 0 Temp1 12C_IsTransmitCompleted while User_Timeout_Function amp amp Temp1 12C_TX_BUFFER_ONGOING Temp1 12C_IsTransmitCompleted To be sure that the communication by this point has been completed if User Timeout Function switch Templ case I2C TX AF case I2C TX BERR 103 235 Function Descriptions 104 235 User Function Error Management break case I2C DATA TX OK Transmission successful break default If none of the above condition is true User Function break I2C_Generate_Stop while 12C_IsStopGen endif Communication mode defined as ITDRV WITHOUTBUF RX in ST7lib config h Single byte reception ifdef I2C ITDRV WITHOUTBUF RX I2C Generate Start while I2C IsTransmitCompleted I2C START OK I2C Load Address Addr Byte Tx I2C RX MODE Timeoutcount 0 Templ I2C_IsTransmitCompleted while User Timeout Function amp amp Templ I2C ADD TX OK Templ 12C_IsTransmitCompleted switch Temp1 To check address transmission status case I2C_TX_AF User Function break default break Timeoutcount 0 Temp2 12C_IsReceptionCompleted while User_Timeout_Function amp am
208. t Parameters I2C RX ARLO If Arbitration lost is detected I2C RX BERR If misplaced start or stop condition is detected I2C RX AF If Acknowledge failure has occurred I2C DATA RX OK If the data reception is completed without any error I2C RX BUFFER ONGOING User buffer is not full I2C RX DATA EMPTY If no data byte is received Required Preconditions Functions called None None Postconditions 1 For single byte reception if the byte is received then 12C_GetByte can be called after this function 2 12C_Error_Clear can be called to clear the error and sta tus flags if required See also None 1 This is applicable only in multimaster 12C devices 2 These Parameters are returned in I2C Interrupt driven mode only 3 This Parameter is returned in case of single byte reception only for both I2C Polling and I2C Interrupt driven modes Notes The above function is for I2C Polling or I2C Interrupt driven mode In I2C Polling mode this function is used in conjunction with I2C GetByte only If this function is called before any reception reguest is made it will check for a single byte reception and will return I2C RX DATA EMPTY until the first data byte is received and ky 95 235 Function Descriptions returns the reception status afterwards If a reception request is over this function will return the error status of that request only once If this funct
209. t Parameters If TRUE flag is set If FALSE flag is not set Required Preconditions LART configured in any one of the modes Functions called None If the output parameter is TRUE flag is set If the output parameter is FALSE the flag is not set and Postconditions this function can be looped till the flag is set LART_Clear_Flag function should be called to clear the flag See also LART_Clear_Flag 1 Feature available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI devices 2 Feature available only on ST7FLite3 device Note All flags except LART_FLAG_ICF also get cleared by calling this function so need to call LART_Clear_Flag function again to clear the flag 3 177 235 Function Descriptions Table 122 LART_Clear_Flag Function Name Function Prototype LART_Clear_Flag Void LART_Clear_Flag Lart_Flag FLAG_F Behaviour Description Input Parameters Clears the status flag depending upon the input parameter passed This function can be called more than once to clear more than one flag FLAG_F LART_FLAG_OVF Clears Overflow flag LART_FLAG_CMPFO Clears Output Compare 0 flag LART FLAG CMPF1 Clears Output Compare 1 flag LART FLAG CMPF2 Clears Output Compare 2 flag LART FLAG CMPF3 Clears Output Compare 3 flag LART FLAG ICF Clears Input Capture flag LART FLAG OVF2 Clears counter 2 overflow flag Output Parameters Reguired Preconditions None Any of LART flags is set
210. ta type definitions and function prototypes for the driver functions Can_hr h This file contains the define statements for the driver functions User c This file contains the Global data declaration which is used by both driver as well as application For example Tx amp Rx buffers Tx amp Rx Id Confirmation amp Indication flags etc User h This file contains all user configurable parameters For example size of Tx amp Rx buffers Number of Tx amp Rx messages hardware registers initialization values etc Note User c and User h can be configured by the user depending on the application 6 2 4 2 DATA STRUCTURES Init Structure Init structure contains the initialization values for the CAN controller registers The user appli cation may have more than one Init Structures which is configured by the parameter NO_OF_INIT_HANDLES The init handle is used as an index for the init structure Transmit Structure The transmit structure contains the information about the transmitted message for example tx Id tx_dlc tx buffer There is a separate table each for Id dic pointer to tx buffer The number of transmit structures depends on the number of messages to be transmitted in an ap plication It is configured by the parameter NO_OF_TX_HANDLES The tx_handle is used as an index for each transmit structure The tx_identifier has two tables one table each for standard and extended identifiers The tx_id tx dlc tables are config
211. tents tents tents tents tents A x 225 235 Function Descriptions unsigned char IO_PIN_6 unsigned char 1O_PIN_7 IO Input IO FLOATING IO PORT D unsigned char IO_PIN_2 unsigned char IO PIN 3 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO_PIN_6 unsignedchar IO PIN 7 IO Input IO_PULL_UP IO_PORT_E unsigned char Io PIN 2 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO PIN 5 unsigned char IO PIN 6 unsigned char IO PIN 7 IO Input IO FLOATING IO PORT F unsigned char IO PIN 2 unsigned char IO PIN 3 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO PIN 6 unsigned char IO_ IO Input IO PULL UP IT IO PORT B unsigned char IO_PIN_2 PIN 7 unsigned char IO PIN 3 unsigned char IO PIN 4 unsigned char IO PIN 5 unsigned char IO PIN 6 unsigned char IO_ IO Output IO PUSH PULL IO PORT B unsigned char IO PIN 1 unsigned char IO_PIN_2 unsigned char IO PIN 3 PIN 7 unsigned char IO_PIN_4 unsigned char IO_PIN_5 unsigned char IO PIN 6 unsigned char IO PIN 7 IO Output IO OPEN DRAIN IO PORT A unsigned char IO PIN 0 unsigned char IO_PIN_2 unsigned char IO PIN 3 unsigned char IO_PIN_4 unsigned char IO_PIN_5
212. th counter value O 3 Output Compare register 3 value is compared with counter value Input Parameter 2 PWMART POLARITY 0 Output level is low for Counter value gt Compare Data Output level is high for Counter value lt Compare Data PWMART POLARITY 1 Output level is high for Counter value gt Compare Data Output level is low for Counter value lt Compare Data Input Parameter 3 Compare Data Data to be loaded in DCR register 0x00 to OxFF Output Parameters Reguired Preconditions None PWMART Counter Enable must have been called Functions called Postconditions None The output compare waveform is obtained on the corre sponding PWM pin See also 3 None 161 235 Function Descriptions Table 109 PYMART OCMP Timebase Function Name Function Prototype PWMART OCMP Timebase Void PWMART_OCMP_Timebase double Tinput double Time Pwmart Clock SELECT CLK Behaviour Description Input Parameter 1 Input Parameter 2 Input Parameter 3 Output Parameters Sets the output compare to be used as time base interrupt Interrupt is generated after every fixed time base inter val depending upon the value of input parameter 2 Tinput You have to pass this value in nano second ns Tinput 1 Fcpu or Tinput 1 Fext in case of external clock Time You have to pass this time base value in nano second ns PWMART CLK PR where PR can be 1 2 4 8 16
213. th for the message s to be received The length of the table is the same as defined by the parameter NO_OF_RX_HANDLES and the value s stored inside the table is are the same as defined by the parameter TX MSGx DLC in the file user h 10 rx data ptr This pointer table stores the address of receive buffer s MSGx Rx Buffer The length of the table is the same as defined by the parameter NO_OF_RX_HANDLES in the file user h 6 2 4 6 Tx 8 Rx BUFFER USAGE Data can be accessed through the Tx amp Rx buffers using the tx handle 8 rx handle as an index For example data can be written into the MSGx Tx Buffer using the pointer tx data ptr x where x tx handle for the message Similarly data can be received from MSGx Rx Buffer using the pointer rx data ptr x where x rx handle for the message 6 2 4 7 IMPLEMENTATION HINTS CanSleep service must not be called when message transmission is in progress otherwise sleep mode is not entered and service returns KCANFAILED Also CanTransmit service shall not be called while the CAN driver is in sleep mode Confirmation flag is set by the driver after the successful transmission of a message and flag has to be cleared by the application Application must call CanInterruptDisable and Can InterruptRestore services when clearing the confirmation flag in order to avoid CAN inter rupt Indication flag is set by the driver for a message received and this flag has to be cleared by
214. th some timeout protection inside this mechanism This mech anism can only be used with the SPI in half duplex mode To use this mode you must have se lected the following define labels inside the ST7lib config h file SPI POLLING TX For Transmission mode SPI POLLING RX For Reception mode Interrupt driven without communication buffer Data can be Transmitted Received both in single as well as continuous mode through the in terrupt driven mechanism In the continuous mode the user data is directly being read written from to the addresses passed by the user After each byte of data transfer an interrupt is ac knowledged and the control goes to the interrupt subroutine The main advantage of using in terrupts rather than polling is that control does not stay in the function till the last data is Trans mitted Received and hence the SPI can be used in full duplex mode Here you should take care not to read write the user buffer until the Transmission Reception completion To use this mode you must select the following define labels inside the ST7lib_config h file SPI ITDRV WITHOUTBUF TX For Transmission SPI ITDRV WITHOUTBUF RX For Reception Notes 1 If both SPI ITDRV WITHOUTBUF TX and SPI ITDRV WITHOUTBUF RX are defined in full duplex mode then the program will perform either transmission or reception only trans mission as per the present structure since the peripheral has a single interrupt for both Transmission and Receptio
215. tions are called in the main Tree and the interrupt Tree the function Reentrant error occurs in case COSMIC compiler is used with models other than stack models Functions description The lt hr h is to be included when the actual hardware register are read to clear the flags For configuring the port pins I O library is used KKK KK K K K K K K K K RARA REE RR RARA RAR RRA K K K A K K ARA RARA RR KK KKK KKK A RRA A RR RAR RRA RARAS Hifdef HIWARE Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved else ifdef COSMIC Test for Cosmic Compiler interrupt nostack telse error Unsupported Compiler Compiler Defines not found endif endif void LT_TB_IT_Routine void unsigned char Temp i LTCSR Clear ICF LT Clear Flag LT FLAG TBF Call only to clear TBF Routine up to the user count if count 5000 Temp IO Read IO PORT B TO Toggle PB3 if Temp 0x08 IO Write IO PORT B IO PIN 3 IO0 DATA LOW Turn OFF LED at PB3 else IO Write IO_PORT_B IO_PIN_3 1I0_DATA_HIGH Turn ON LED at PB3 count 0 158 235 3 Function Descriptions 9 1 9 PWMART This software library for PWMART consists of the following functions Function Name PWMART Init Function Prototype Behaviour Description Void PWMART Init Typ Pwmart InitParameter InitVal ue Initialization of the P
216. transmission and all data bytes are transmitted I2C TX BUFFER ONGOING If all the data bytes from user buffer are not transmitted I2C TX STRING ONGOING If the complete string is not transmitted None Functions called Postconditions None I2C Error Clear can be called to clear the error and status flags if reguired See also None 1 This is applicable only in multimaster I2C device 2 These Parameters are returned in I2C interrupt driven mode only Notes The above function is for I2C Polling or 12C Interrupt driven mode In I2C Polling mode this function is used in conjunction with I2C PutByte only 3 91 235 Function Descriptions Table 54 12C_GetByte Function Name Function Prototype I2C GetByte Unsigned char I2C_GetByte void Behaviour Description Input Parameters Returns the most recent Byte received in I2C Polling or 12C interrupt driven mode None Output Parameters Unsigned char Returns the received data byte Reguired Preconditions 1 12C Load Address must have been called if master re ceiver 2 You must define I2C Polling or I2C interrupt driven re ception mode in ST7lib config h 3 12C_IsReceptionCompleted must have been called to ensure that there are no pending reguests and also to check if data byte has been received or not 4 You must enable interrupts for I2C interrupt driven mode 5 In 12C Interrupt driven mode
217. ts u o L A S EL E AAA AAA E S A A Transmission through Polling mechanism Sao EE a E VE E ee Se E Z E n E E E LZ Z N E ifdef SCI POLLING TX Selects polling mode for transmission SCI Mode SCI TX ENABLE SCI PutByte Tx Data Single Byte transmission Bool Templ SCI IsTransmitCompleted this function causes a volatile variable to change hence it cannot be put as a right side operand in a conditional stmt while User Timeout Function amp amp Bool Templ SCI PutBuffer Buff NbofBytes Continuous buffer transmission endif E m re A A ee se ee Ee ee ee ee es ee Reception Through Polling mechanism AA AR A n as ra i A a a ep ee ifdef SCI POLLING RX Selects polling mode for reception SCI Mode SCI RX ENABLE Enable the receiver mode of SCI PES AA AS SA E Single Byte Reception s do Wait for data reception Err SCI IsReceptionCompleted 54 235 ISA Function Descriptions j while User_Timeout_Function amp amp Err SCI RX DATA EMPTY if User Timeout Function Byte received before Timeout if Err SCI RECEIVE OK Rx Data SCI GetByte Correct Data Byte received Nop else if unsigned char Err amp SCI NOISE ERR Userfunction if unsigned char Err amp SCI_OVERRUN_ERR Userfunction if unsigned char Err amp SCI FRAMING ERR Userfunction i
218. u must enable interrupts for this mode 4 For SPI Interrupt driven mode SPI IT Function must have been called in the Interrupt service routine Required Preconditions Functions called None SPI IsTransmitCompleted can be called after this function to get the transmission status SPI IsTransmitCompleted SPI PutString SPI Polling mode Postconditions See also Notes The above function is only for SPI Interrupt driven mode For software slave mode transmission you must define SPI SLAVE CONFIG in ST7lib_config h Caution Do not access the string until transmission is completed Data transmission will stop if any error occurs during transmission 3 64 235 Function Descriptions Table 34 SPI PutBuffer Function Name Function Prototype SPI_PutBuffer Void SPI PutBuffer const unsigned char PtrToBuffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Starts transmission of data in the interrupt service routine from the user defined area for SPI Interrupt driven mode PtrToBuffer Start address of the user buffer NbOfBytes Number of data bytes to be transmitted None Required Preconditions 1 The SPI should be configured correctly 2 You must define the transmission mode as SPI Inter rupt driven in ST7lib config h 3 You must enable interrupts for this mode 4 For SPI Interrupt driven
219. uired Preconditions Functions called None Postconditions ADC correctly configured See also ADC_Enable and ADC_Select_Channel 1 Speed bit is present in ST72F561 ST72F62 ST72F264 ST72F521 ST72325 ST7232A ST7DALI ST7FLITEO 1 2 3 and ST7SUPERLITE 2 Slow bit is present in ST72F561 ST72F264 ST7DALI ST7FLITEO 1 2 3 and ST7SUPERLITE 3 Feature present only in ST72F62 4 Amplifier present in ST7DALI ST7FLITEO 1 2 and ST7SUPERLITE x 30 235 Function Descriptions Table 2 ADC_Select_Channel Function Name Function Prototype ADC Select Channel Void ADC Select Channel unsigned char ADC AIN Behaviour Description Input Parameters Selects the conversion channel by passing the channel number as input parameter ADC AIN ADC AIN is in the range 0 15 The channel number depends on the device please refer to the corresponding datasheet Output Parameters Reguired Preconditions Functions called None 1 ADC Ini must have been called 2 The selected channel must be configured as floating in put None Postconditions ADC channel selected See also ADC Enable Table 3 ADC Enable Function Name ADC Enable Function Prototype Behaviour Description Void ADC Enable void Switches on the ADC to start conversion on the selected channel Input Parameters Output Parameters None None Reguired Preconditions Functions called ADC Select Cha
220. uired Preconditions Functions called Timer8 must be configured in any one of the modes None Postconditions If TRUE timer8 flag is set and can be cleared by calling TIMER8_Clear_Flag If FALSE timer8 flag is not set and this function can be looped till the flag is set See also 3 TIMER8 Clear Flag 145 235 Function Descriptions Table 95 TIMER8_Mode_Disable Function Name Function Prototype TIMER8_Mode_Disable Void TIMER8_Mode_Disable Timer8_Mode MODE_M Behaviour Description Input Parameter Disables the timer8 mode depending upon the Input pa rameter passed This function should be called more than once in order to disable more than one mode TIMER8 MODE M where M can be 1 2 3 4 5 6 7 8 9 M 1 Output compare1 mode OCMP1 M 2 Output compare2 mode OCMP2 M 3 Input capture1 mode ICAP1 M 4 Input capture2 mode ICAP2 M 5 Pulse width modulation mode PWM M 6 One pulse modulation mode OPM M 7 Forced compare1 mode FORCDCMP1 M 8 Forced compare2 mode FORCDCMP2 M 9 Timer prescalar counter and outputs disabled Output Parameters Reguired Preconditions None Timer8 active in any of the modes Functions called Postconditions None Selected timer8 mode is disabled and the Corresponding status flag is cleared See also 146 235 None 3 Function Descriptions Table 96 TIMER8_Clear_Flag Function Name Function P
221. unt lt 50000 Timeoutcount return TRUE return FALSE void User_Function void SPI_Clear_Flags 80 235 SPI Interrupt service routine function Time out not elapsed Time out elapsed Clears error and status flags 3 Function Descriptions 9 1 4 12C MASTER Following are the functions related to both Single master and multi master 12C Function Name I2C Init Function Prototype Behaviour Description Input Parameters Output Parameters Void 12C_Init I2C Init Param Init Value Initialization of I2C By default 12C peripheral is enabled acknowledge and interrupts are disabled If single master 12C device is selected I2C will be idle You can change the default configuration by selecting the input parameters given below You can pass one or more parameters by logically OR ing them I2C DEFAULT PARAM1 Load all 12C registers with default value Only I2C periph eral is enabled PE bit is set I2C ENABLE ACK Enables acknowledge I2C IT ENABLE Enables interrupt None Reguired Preconditions 1 I O port should be configured correctly 2 If you want to configure single master 12C the ST72F65 device must be selected Functions called Postconditions None 1 If you want to enable interrupts the I2C IT ENABLE parameter has to be passed in the 12C_Init function After the 12C_Init function is called you should use the Ena ble
222. upt Priority FOR EI0O AS LEVEL 2 ITC SetPriority IT EI2 IT LEVEL 1 Sets Interrupt Priority FOR EI2 AS LEVEL 1 Priority ITC GetPriority IT EI0 Gets Priority while ITC Get CurrentLevel IT LEVEL 3 Checks Current interrupt priority ITC ConfigureInterrupt IT PortA Pin IT EDGE F Set falling edge sensitivity for EI0 ITC ConfigureInterrupt IT_PortB Pin IT EDGE F Set falling edge sensitivity for EI2 ITC DisableTLI Disables TLI interrupt ITC TLISensitivity IT EDGE R Sets Rising edge for TLI ITC EnableTLI Enables TLI interrupt FERRERA RARE KA K KA K K KA K KA K K K A K KA K K K A KK K K KK A K KK K KA K K K K KKK K K KK RRE RAR k k k k RR k k k k k k k k Interrupt Subroutine for TLI KKKKA KKK KK KA KK A K KK K K KA K KK K K KA K KK K K KA KKK KK KA KKK K KK A KKK KKK K K KA KKK K K KA K K KKK K KK ifdef HIWARE Test for HIWARE Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved telse ifdef _COSMIC_ Test for Cosmic Compiler interrupt Cosmic interrupt handling else error Unsupported Compiler Compiler Defines not found endif endif void TLI_IT_Routine void unsigned int i PDDDR 0x04 PDOR 0x04 PDDR 0x04 for i 0 i lt 5000 i Nop y PDDR amp OxFB FERRERA RARE RE RARE K K KA KK EK ER A K KA K KER KR EK KK RRR RK KK RK RRE RE
223. upt service routine Otherwise data transfer synchronisation will be affected which may lead to data loss or overrun error Table 43 SPI_Clear_Flags Function Name SPI_Clear_Flags Function Prototype Void SPI_Clear_Flags void Clears the SPI error WCOL MODF and OVR bits of SPICSR register and status SPIF bit of SPICSR flags Input Parameters None Output Parameters None Required Preconditions Transmission or Reception must have taken place Functions called None Postconditions None Behaviour Description See also SPI IsTransmitCompleted SPI IsReceptionCompleted Note You can call this function whenever you want to force the error and status flags to be cleared Caution Do not call this function if a reception reguest is ongoing as it will corrupt the recep tion status by clearing all the flags and you will not receive any error status 3 73 235 Function Descriptions EXAMPLE The following C program shows the use of SPI functions Program Description This program runs the following sequence for the SPI for SPI Polling and SPI Interrupt driven modes 1 Transmits a single byte passed by the user and receives single byte of data 2 Transmits and receives the 10 bytes of data You can select one pair of the following communication modes for transmission and reception respectively SPI_POLLING_TX For Transmission mode SPI_POLLING_RX For Reception mode SPI ITDRV WITHOUTBUF TX For
224. ured by the user as per the message to be transmitted There is a single bit confirmation flag for each transmit mes sage Receive Structure The receive structure contains the information about the received message for example rx Id rx_dlc rx buffer There is separate table each for Id dic pointer to rx buffer The number of receive structures depends up on number of messages to be received in an appli cation It is configured by the parameter NO_OF_RX_HANDLES The rx handle is used as an index for each receive structure The rx_identifier has two tables one table each for standard and ex tended identifiers The identifier for the received message is stored inside this table by the driver The rx dlc is configured by the user as per the length of the message There is a single bit indication flag and overflow flag for each received message 3 22 235 How to use the library 6 2 4 3 DATA TYPES The following are the data types used by the driver canuint8 8 bit unsigned integer canuint16 16 bit unsigned integer There are some data types referenced while calling driver function CanlnitHandle 8 bit unsigned integer application specific depends on the number of con figured initialization modes CanTransmitHandle 8 bit unsigned integer application specific depends on the number of transmit objects tCanMsgObject typedef volatile struct canuint16 stdid canuint16 extid canuint8 dlc canuint8 data 8 This
225. ut Parameter 3 PWMChannel LART_PWMO PWM channel 0 is configured LART PWM1 PWM channel 1 is configured LART PWM2 PWM channel 2 is configued LART PWM3 PWM channel 3 is configured Autoreload Value This value is loaded in autoreload register ATR You can select this value from 0x000 to OxFFF depending on the freguency reguired for the PWM signal LART POLARITY 0 PWM output level is low for Counter value gt Dutycycle Data PWM output level is high for Counter value lt Dutycycle Data LART POLARITY 1 PWM output level is high for Counter value gt Dutycycle Data PWM output level is low for Counter value lt Dutycycle Data Input Parameter 4 Output Parameters Dutycycle Data Data to be loaded in Duty cycle register 0x000 to OxFFF Note This value must be greater than the ATR register value loaded through Input parameter 1 to obtain signal on PWMx pin None Required Preconditions Functions called LART_Init must have been called to select the counter clock None 174 235 x Function Descriptions PWM signal of required frequency and duty cycle is gen Postconditions erated at PWMx pin The output compare mode is disa bled See also LART_Init 1 Feature available only for ST7FLite1 ST7FLite2 ST7FLite3 and ST7DALI devices Note This function configures only one PWM channel at one time So to configure multiple PWM Channels this function
226. utString 12C_TxErrCode_t I2C PutString const unsigned char PtrToString Behaviour Description Input Parameters Output Parameters Reguired Preconditions Transmits data string in I2C Polling mode from the user defined area Data transmission will stop if any error oc curs during transmission The transmission status will be returned PtrToString Start address of the user string 12C_TX_AF If Acknowledge failure has occurred 12C_TX_ARLO If Arbitration lost is detected 12C_TX_BERR If misplaced start or stop condition detected I2C DATA TX OK If there is no error in transmission 1 12C Load Address must have been called If 12C is configured in master transmitter mode 2 You must define I2C Polling mode in ST7lib config h Functions called Postconditions None None See also 12C_PutString 12C Interrupt driven mode This is applicable only in multimaster 12C Note The above function is only for I2C Polling mode Caution The application can lose control if the 12C is disabled while using this function 3 87 235 Function Descriptions Table 50 12C_PutBuffer Function Name Function Prototype I2C PutBuffer I2C TxErrCode t I2C PutBuffer const unsigned char PtrToBuffer unsigned char NbOfBytes Behaviour Description Input Parameter 1 Input Parameter 2 Output Parameters Transmits data string in I2C Polling mode from the user defined area The dat
227. ve Task Services Table 180 CanTx ISR This service returns the current status of the CAN controller Function Name Function Prototype CanTx ISR void CanTx ISR void Input Parameters Output Parameters None None Behaviour Description Table 181 CanRx ISR This service handles the wakeup error and trans mit mailbox empty interrupts Wakeup and Error interrupt flags are cleared for wakeup and error interrupts In the event of transmit interrupt the confirmation flag is set for the message transmit ted Note confirmation is raised for the messages re quested by service CanTransmit Function Name Function Prototype CanRx_ISR void CanRx_ISR void Input Parameters Output Parameters None None Behaviour Description This service handles the receive FIFO interrupt Received message CAN ID CAN DATA is cop ied into the Rx buffer corresponding to the mes sage received Rx buffer into which data is copied is identified by the filter match index The Indication flag is set for the message received 3 231 235 Function Descriptions 9 2 1 6 Interrupt Services Table 182 CanGloballnterruptDisable Function Name Function Prototype Input Parameters Output Parameters CanGloballnterruptDisable void CanGloballnterruptDisable void None None Behaviour Description This service disables the interrupt by setting the global interrupt flag o
228. z and duty cycle of 30 Generate PWM at PWMO pin LART_PWM_Mode unsigned int 0xCE0 LART POLARITY 0 unsigned int 0xDDO while 1 VA EE pe A i A AA AAA V m V ka A ee E E A et ROUTINE NAME LART OVF IT Routine INPUT None OUTPUT None DESCRIPTION Interrupt service routine for Overflow interrupt COMMENTS This gets automatically executed when OVF interrupt of the LART is enabled If the same functions are called in the main Tree and the interrupt Tree the function Re entrant error occurs in case COSMIC compiler is used with models other than stack models For configuring the port pins I O library is used aaa a SS Ss Ss iS SS SS ifdef _HIWARE_ Test for Metrowerks Compiler pragma TRAP_PROC SAVE_REGS Additional registers will be saved else ifdef _COSMIC_ Test for Cosmic Compiler interrupt nostack else error Unsupported Compiler Compiler Defines not found endif endif S72 185 235 Function Descriptions void LART_OVF_IT_Routine void unsigned char Temp LART Clear Flag LART FLAG OVF Call to clear OVF count if count 10000 Temp IO Read IO PORT B TO Toggle PB3 if Temp 0x08 IO Write IO PORT B IO PIN 3 IO0 DATA LOW Turn OFF LED at PB3 else IO Write IO_PORT_B IO_PIN_3 1I0_DATA_HIGH Turn ON LED at PB3 count 0 186 235 3 Function Descriptions 9 1 11 TBU This software library
Download Pdf Manuals
Related Search
Related Contents
取扱説明書 取扱説明書 trace Total Chlorine concentrations Hunter PermaLife Manual for 3537003 Metériel Mode d`emploi - Support Tango Device Server User's Guide DE EN FR ES IT NL PT ODYS MP3-Player S16 ODYS MP3 player Center stand - Harley Executivos recorrem à Justiça do Trabalho Copyright © All rights reserved.
Failed to retrieve file