Home
SUB-20 User Manual
Contents
1. 8 or grater Library version 1 0 1 0 1 12 10 or grater 3 7 9 2 sub pwm set Synopsis int sub pwm set sub handle hndl int pwm n int duty Configure specific PWM output Parameters pwm n number of PWM output to configure Can be 0 7 duty Duty cycle in range 0 255 Duty cycle If duty cycle is O PWM output will be constantly low If duty cycle is grater or equal to the limit set by sub pwm config PWM output will be constantly high Effective duty cycle in percent can be calculated as DUTY duty limit 100 Duty cycle resolution in bits depends on limit It can be in range of 1 bit for limit 2 up to 8 bit for limit 255 Return value On success function returns 0 Otherwise error code Example Set PWM resolution 10ms limit 100 freguency 1Hz sub_pwm_config hndl 10000 100 Set PWM 0 pin GPIO24 to output state sub_gpio_config hndl 0x01000000 amp config 0x01000000 Output 50 duty cycle on PWM 0 pin 2013 xdimax com rev 2 17 45 SUB 20 SUB 20 API sub_pwm_set hndl 0 50 See also sub pwm config Error Codes Compatibility FW version 8 or grater Library version 1 0 1 0 1 12 10 or grater 3 8 Analog to Digital Converter ADC SUB 20 has 8 single ended and a 16 differential analog input combinations with x1 x10 or x200 input gain amplifier Analog inputs are referenced as ADCO ADC7 see GPIO Header The SUB 20 ADC module features
2. If ss config is zero there will be no SS activity changes Return value On success function returns 0 Otherwise error code Example Transmit one byte and receive 3 bytes SS1 goes low during transaction sub sdio transfer hndl out buf in buf 1 3 SS CONF 1 SS LO Compatibility FW version 9 or grater Library version 1 0 1 0 1 12 11 or grater 2013 xdimax com rev 2 17 32 SUB 20 SUB 20 API 3 6 MDIO Functions MDIO is a Management Data Input Output Interface defined in IEEE 802 3 Clause 22 and extended in Clause 45 It is two signal based interface between Station Management SUB 20 in our case and a Physical Layer device PHY Where a PHY or grouping of PHY s is an individually manageable entity known as an MDIO Manageable Device MMD Signals MDC management data clock MDC is sourced by SUB 20 to the PHY as the timing reference for transfer of information on the MDIO signal MDIO management data input output MDIO is a bidirectional signal between PHY and the SUB 20 It is used to transfer control information and status between the PHY and the SUB 20 Control information is driven by the SUB 20 synchronously with respect to MDC and is sampled synchronously by the PHY Status information is driven by the PHY synchronously with respect to MDC and is sampled synchronously by the SUB 20 Frame Format SUB 20 supports both MDIO frame formats defined in IEEE 802 3 Clause 22 and Cl
3. int sub mdio xfer ex sub handle hndl int channel int count union sub mdio frame mdios Generate a seguence of independent MDIO frames Frames in seguence can be Clause 22 or Clause 45 format with different operations and addresses Parameters channel mdio channel see MDIO Channels Optional SUB CFP MSA flag applied to channel channel SUB CFP MSA will force SUB 20 to generate CFP MSA compatible transaction s at 4MHz MDC freguency count number of frames to generate currently up to 15 mdios array of count sub mdio frame unions union sub mdio frame Struct int op int phyad int regad int data clause22 Struct int OP int prtad int devad int data clause45 Frame operation is defined by op field value clause22 0p can be SUB MDIO22 READ READ operation SUB MDI022 WRITE WRITE operation clause45 op can be SUB MDIO45 ADDR ADDRESS operation SUB MDIO45 WRITE WRITE operation SUB MDIO45 PRIA POST READ INCREMENT ADDRESS operation 2013 xdimax com rev 2 17 35 SUB 20 SUB 20 API SUB MDIO45 READ READ operation For READ and POST READ INCREMENT ADDRESS operations clause22 data or clause45 data will be filled with data read from PHY Return value On success function returns 0 Otherwise error code Example union sub mdio frame mdios 2 mdios 0 clause22 op SUB MDTI022 READ mdios 0 clause22 phyad 0x01 mdios 0 clause22 regad
4. sub fifo write 2013 xdimax com rev 2 17 52 SUB 20 SUB 20 API 3 11 1 1 sub fifo config Synopsis int sub fifo config sub handle hndl int config Configure FIFO Parameters config set of FIFO configuration flags listed below FIFO SELECT SPI Connect SPI module to FIFO FIFO_SELECT_I2C Connect I2C slave module to FIFO FIFO_SELECT_UART Connect UART to FIFO FIFO_CLEAR Clear IN and OUT FIFO buffers FIFO_READ_FULL Read only full 64 byte FIFO buffers Return value On success function returns 0 Otherwise error code Compatibility FW version FIFO_CLEAR 0 1 3 or grater FIFO_SELECT_UART 0 2 0 or grater Library version 0 1 12 10 or grater 3 11 1 2 sub fifo write Synopsis int sub fifo write sub handle hndl char buf int sz int to ms Function attempts to transfer sz bytes from buffer into OUT FIFO in no more then to ms time Parameters buf source buffer sz buffer size to ms timeout in milliseconds Return Value On success a non negative number of actually written bytes is returned It can be less then or equal to sz In case of error negative error code defined in errno h will be returned and if applicable sub errno will be set to the corresponding value Possible error codes are ENOENT 2 USB failure EIO 5 USB failure ENOMEM 12 Memory failure EINVAL 22 Invalid parameter EFBIG 27 Buffer overflow ETIMEDOUT 116 Timeout 3 11 1 3 sub_fi
5. Error Codes 3 7 3 sub gpio write Synopsis int sub_gpio_write sub_handle hndl int set int get int mask Set GPIO output status For GPIO in output state function will set output driver to drive 1 high 0 low For 2013 xdimax com rev 2 17 38 SUB 20 SUB 20 API GPIO in input state function will 1 enable 0 disable weak pull up on corresponding GPIO pin Parameters set Bits 0 31 of set parameter correspond to GPIOO GPIO31 output statuses get Pointer to store current GPIO output status read from SUB 20 mask Bit in set parameter will take effect only if corresponding mask bit is 1 With mask 0 function will only read current GPIO output status Return value On success function returns O Otherwise error code See also Error Codes 3 7 4 sub gpiob config Synopsis int sub_gpiob_config sub_handle hndl int set int get int mask Configure GPIOB state direction as input or output Parameters set Bits 0 7 of set parameter correspond to GPIOBO GPIOB7 configuration bits If GPIOBn configuration bit is 1 then GPIOBn direction is output otherwise it is input get Pointer to store current GPIOB configuration read from SUB 20 mask Bit in set parameter will take effect only if corresponding mask bit is 1 With mask 0 function will only read current GPIOB configuration Return value On success function returns 0 Otherwise error code See also Error Codes Compati
6. If required read data from FIFO with sub fifo read This will be data written by external I2C master Transactions SUB 20 12C slave module acts as zero address 12C slave device Below are diagrams of receive and transmit transactions Slave receive A Address JE Address Slave transmit 3 Slave 3 12 Error Codes API functions may return error code and or set global variable sub_errno to provide information about completion of requested operation The string describing error code can be received with sub_strerror function call 3 12 1 sub errno Global variable sub_errno contains status of last SUB 20 API call Variable sub errno defined in ibsub h Following error codes are available 0 OK 1 SUB Device not found 2 Can t open SUB device 3 Can t set configuration 2013 xdimax com rev 2 17 55 SUB 20 SUB 20 API 4 Can t claim interface 5 Failed to setup async transaction 6 Failed to submit async transaction 7 Bulk write failed 8 Bulk read failed 9 Bulk read incomplete 10 Out buffer overflow 11 12C error 12 Wrong tag code in response 13 Wrong tag size in response 14 Wrong parameters 15 SPI Disabled 16 Feature not supported 17 Timeout 18 Init Failed 19 Bad Handle 20 InfraRed Failure 3 12 2 sub_strerror Synopsis char sub_strerror int errnum Return string describing error number This function is similar to strerror Parameters errnum error n
7. SPI_CPOL_FALL Sample mosi in H EH KH HK HK EH EE eee SS io de ol aa os MISO Pin OO H tH tH HR HE OHM pon i IN i i m i A i IN PAL 2013 xdimax com rev 2 17 27 SUB 20 SUB 20 API SPI Transfer format with SPI_SETUP_SMPL SEL CPOL RISE SPI CPOL FALL Most Pin Mi H L T T L L ER ee eee Or n A AY 3 AY f t VF V MISO Pin CH H KH E T I T j A i PA i IN i F A H i J H Functions sub spi config sub spi transfer sub spi transfer ess sub sdio transfer 3 5 1 sub spi config Synopsis int sub spi config sub handle hndl int cfg set int cfg get Configure SUB 20 SPI module or read current configuration If efg get is NULL function will configure SPI according to the cfg set parameter Otherwise it will read current SPI configuration into efg get Parameters cf g set Desired SPI configuration This parameter is effective only if efg get is NULL cfg set should be assembled as a combination of below flags SPI ENABLE Enable SUB 20 SPI module SPI SLAVE SPI module is in Slave mode sub spi transfer can work only when SPI module is in Master mode E SPI CP R RTS SCK is low when idle See SPI Polarity and Phase explanations SPI_CPOL_FALL SCK is high when idle See SPI Polarity and Phase explanations SPI_SMPL_SE
8. sub handle hndl int mcode int count struct sub i2c hs xfer px Perform High Speed HS I2C Master read write transaction s with prior master code transmit according to 12C bus specification The whole session has the following format Jajsew E JLE High Speed Mode Slave At the beginning of the session both master and slave are in Fast Speed or Standard I2C mode Master issues START condition and transmits Master Code 00001xxx where xxx is under SW control via mcode parameter Master Code 00001000 should not be used as it is reserved by I2C bus specification for future extensions Master Code will not be acknowledged NAK will be generated At the end of NAK I2C bus is in HS mode Now master can perform HS read write transactions by issuing REPEATED START condition followed by Slave Address with R W bit and data byte s being read written according to R W bit To exit HS mode master issues STOP condition A number of HS transactions can be performed within single HS mode session it is recommended by 12C bus specification Parameters mcode Master Code lower 3 bits count number of HS mode read write transactions to perform px pointer to array of count transaction descriptors of type struct sub i2c hs xfer struct sub i2c hs xfer ine sa int rw int sz E act 825 char data 64 int status 2013 xdimax com rev 2 17 22 SUB 20 SUB 20 API y where
9. 0 API 3 7 8 1 sub_fpwm_config Synopsis int sub fpwm config sub handle hndl double freq hz int flags Configure fast PWM module Parameters freq_hz Desired fast PWM frequency in Hz Frequency can be in a range 8MHz 0 238Hz flags Set of configuration flags listed below FPWM_ENABLE General fast PWM enable If this flag is not set fast PWM module will be disabled and FPWM outputs will go to HiZ FPWM_ENO Enable FPWM_0 output Otherwise FPWM_0 will stay low FPWM EN1 Enable FPWM 1 output Otherwise FPWM 1 will stay low FPWM EN2 Enable FPWM_2 output Otherwise FPWM 2 will stay low Return value On success function returns 0 Otherwise error code Example Enable fast PWM module with FPWM 0 and FPWM 2 outputs PWM freguency 10 6Hz 7 sub_fpwm_config hndl 10 6 FPWM ENABLE FPWM ENOFPWM EN2 See also sub fpwm set Error Codes 3 7 8 2 sub fpwm set Synopsis int sub fpwm set sub handle hndl int pwm n double duty Configure specific fast PWM output Parameters pwm n number of FPWM output to configure Can be 0 1 2 duty desired duty cycle in range 0 100 Can be not integer Return value On success function returns 0 Otherwise error code Example sub fpwm set hndl 0 20 sub fpwm set hndl 1 30 5 sub fpwm set hndl 2 12 25 See also sub fpwm config Error Codes 2013 xdimax com rev 2 17 43 SUB 20 SUB 20 API 3
10. 0x12 mdios 1 clause45 op SUB MDIO045 ADDR mdios 1 clause45 prtad 0x04 mdios 1 clause45 devad 0x02 mdios 1 clause45 data Ox55AA rc sub mdio xfer hndl 2 mdios Compatibility sub_mdio_xfer FW version 0 2 1 or grater Library version 0 1 12 12 or grater sub_mdio_xfer_ex FW version 0 2 8 or grater Library version 0 1 12 18 or grater SUB_CFP_MSA FW version 0 3 2 or grater Library version 0 1 12 24 or grater 3 7 GPIO Functions GPIO Functional Description SUB 20 GPIO can be in input or output state GPIO state is defined by configuration bit In output state GPIO will drive high or low level depending on output status In input state GPIO can be pulled high by internal weak pull up resistor 2013 xdimax com rev 2 17 36 SUB 20 SUB 20 API VCC Output Status sub gpio write Input Status sub gpio read Configuration sub gpio config GPIO Pin configuration Output Status Configuration State TT O Input state Output state HIGH GPIOB GPIOB are located on SPI header see SPI Header GPIOB module shares I O pins with SPI module If SPI is enabled MISO MOSI SCK and SSO pins are partially controlled by SPI module although they can be accessed by GPIOB functions with restrictions Special care should be taken for SUB Lxxx models where SPI Level Converters are installed In this case GPIOB pins direction should respect direction of the corresponding Le
11. 2 module is enabled GPIO8 GPIO9 can only be used as inputs Return Value On success function returns 0 Otherwise error code 2013 xdimax com rev 2 17 19 SUB 20 SUB 20 API 3 3 3 sub i2c start Synopsis int sub i2c start sub handle hndl Generate 12C start condition Return value On success function returns 0 Otherwise error code See also Error Codes 12C Status 3 3 4 sub i2c stop Synopsis int sub i2c stop sub handle hndl Generate 12C stop condition Return value On success function returns 0 Otherwise error code See also Error Codes I2C Status 3 3 5 sub i2c scan Synopsis int sub i2c scan sub handle hndl int slave cnt Scan I2C bus looking for connected slave devices Parameters slave cnt Buffer to store number of found slave devices slave buf Buffer to store found slave device addresses Return value On success function returns 0 Otherwise error code See also Error Codes I2C Status 3 3 6 sub i2c read Synopsis int sub i2c read sub handle hndl int sa int ma char slave bu f int ma sz char buf int sz Perform complete I2C master read transaction with optional memory address write Transaction will have 2013 xdimax com rev 2 17 20 SUB 20 SUB 20 API following format J8 SEJN Slave Memory Address Write Data Read If ma_sz is zero Memory Address Write stage will be skipped Function has no l
12. 20 device descriptor or NULL if no more devices were found Returned value can be used as parameter for sub open Device descriptor is not a device handle reguired by API calls Handle is returned by sub open Example sub device dev 0 while dev sub find devices dev Check device serial number 3 1 2 sub open Synopsis sub handle sub open sub device dev Open SUB 20 device If parameter dev is NULL function will try to open first available SUB 20 device In this case it will call internally sub find devices 0 Otherwise function will try to open SUB 20 device referenced by dev If your application intended to work with single SUB 20 device you can always call sub open with dev NULL Return value On success function returns non zero handler that should be used in all subseguent calls to SUB 20 API functions In case of error function returns NULL and set sub errno Example handle sub open 0 if lhandle 2013 xdimax com rev 2 17 15 SUB 20 SUB 20 API printf sub_open s n sub strerror sub errno return 1 3 1 3 sub get serial number Synopsis int sub get serial number sub handle hndl char buf int sz Get serial number string descriptor Parameters buf buffer to store descriptor sz buffer size Return value On success function returns string descriptor size Otherwise negative number Example if sub get serial _number hndl buf sizeof bu
13. 5 bit register address data 16 bit data for WRITE operation content 16 bit register content placeholder for READ operation Return value On success function returns 0 Otherwise error code Example Read register 0x12 in PHY 1 rc sub mdio22 hndl SUB MDIO22 READ 0x01 0x12 0 amp content Write register 0x5 in PHY 2 re sub mdio22 hndl SUB MDIO22 WRITE 0x02 0x05 Ox55AA 0 Compatibility FW version 0 2 1 or grater Library version 0 1 12 12 or grater 3 6 2 sub mdio45 Synopsis int sub mdio45 sub handle hndl int op int prtad int devad int data int content Generate IEEE 802 3 Clause 45 MDIO frame Frame format is shown here Clause 45 MDIO frame Parameters op operation code SUB MDIO45 ADDR ADDRESS operation SUB MDIO45 WRITE WRITE operation SUB MDIO45 PRIA POST READ INCREMENT ADDRESS operation SUB MDIO45 READ READ operation prtad 5 bit port address devad 5 bit device address data 16 bit address or data for ADDRESS or WRITE operation 2013 xdimax com rev 2 17 34 SUB 20 SUB 20 API content 16 bit register content placeholder for READ or POST READ INCREMENT ADDRESS operation Return value On success function returns 0 Otherwise error code Compatibility FW version 0 2 1 or grater Library version 0 1 12 12 or grater 3 6 3 sub mdio xfer sub mdio xfer ex Synopsis int sub mdio xfer sub handle hndl int count union sub mdio frame mdios
14. 7 9 PWM PWM outputs are available on GPIO24 GPIO31 pins see GPIO Header Outputs are referenced as PWM 0 PWM_7 PWM generation module shown below has configurable source clock counter limit and separate comparator for each PWM output PWM clk counter resolution PWM module resolution and limit are configured with sub pwm config Duty cycle of each PWM output can be set with sub pwm set PWM module output signal controls output driver of the corresponding GPIO see GPIO Functions To get high low transition of the GPIO pin it should be configured to output state with sub gpio config Otherwise PWM module will enable disable internal pull up Functions sub fpwm config sub pwm set 3 7 9 1 sub pwm config Synopsis int sub pwm config sub handle hndl int res us int limit Configure PWM module Parameters 2013 xdimax com rev 2 17 44 SUB 20 SUB 20 API res us PWM module clock resolution in us Resolution range is 20us 16384us limit PWM module counter limit in range 0 255 If limit is O PWM module will be turned off PWM frequency Resolution and limit define PWM module frequency Fpwm 1000000 res_us limit Hz PWM frequency range is Fpwm_min 1000000 20 2 25000 Hz 25KHz Fpwm max 1000000 16384 255 0 238 Hz Return value On success function returns 0 Otherwise error code See also sub pwm set Error Codes Compatibility FW version
15. AA dada dwa Gaw 24 SUD DD A126 O 25 SPI F nctli nsa te da wi A AD ou Ka ES ESA due es du da de 26 SUD 0 CONMPIG dia 27 UA SO A AI etes duree etes EE ROWE POD SEP es nee nues eo Can 28 sub spi transfer ess 29 SUD SOLO transfer ER OR EEE EE Te ete 30 MDIO FUnCtiONS i iii i wawa wdw w dd add 32 2013 xdimax com Contents 3 sub_mdio22 33 SUD MAIOSS R E A A A ER A nd 33 sub mdio xfer sub imdio Xfer A iii ainia ci aaa 34 7 GPIO FUNCTIONS 0 den nn nana a ky us LE an nn ao aaa nu adu 35 SUD GpPIO CONTIQ sacs ans Se sco a ee nn nee nn en ec ot dues see etes a ends 37 SUD QPIO read a Pause reines 37 sub gpio write 37 SUD o o o 0 O iia 38 sub ADA R ee ne a RS A A 38 SUb GpIob E eee a 39 Edge Detector see ya ae o diodo 39 sub edge config aaa EASE aaa aaa an 40 sub 6dge read 32432 do its 40 Fast PWM NORSE RP O O dina 41 SUD fPWM Oi i 42 sub_fpwm_set du 42 O 43 MN A A ROA 43 SUDMDWIN SSC lites ea z ance K OR EO lene AAA OO o eee 44 8 Analog to Digital Converter ADC 2 ss ssss mees ann a a az nana eee a KKK aaa aa aaa KESA AKASA aa SERA AAAA 45 SUD AOC COMTIG NEST PRS RAA RT EA ON PA PORN RA RAE PAS POOR ORATOR EH 45 sub_adc_single 45 SUB adC A O 45 O EC Dy FU Cui Onn Sci Lu wa cs oe den fraudes dde iai a E d as 47 SUD NCO Ag CN O PR 47 10 RS232 RS485 F CUON S civic ida iaa 48 Sub rs CONIIGI zed nn ren en ne nn
16. B 20 LV SUB 20 LR25 SUB 20 LR45 SUB 20 EB SUB 20 DV SUB 20 DR25 SUB 20 LEB SUB 20 LDV SUB 20 LDR25 2013 xdimax com rev 2 17 58 SUB 20 Ordering Information 2013 xdimax com rev 2 17
17. PL SETUP SPI MSB FIRST SPI CLK 4MHZ 0 Disable SPI sub spi config hndl 0 0 Compatibility SPI CLK HZ FHZ FW version 0 3 3 or grater Library version 0 1 12 25 or grater 3 5 2 sub spi transfer Synopsis int sub spi transfer sub handle hndl char out buf char in buf int sz int ss config Perform SPI master transaction Depending on out buf and in buf parameters transaction can be either read out buf 0 write in buf 0 or read write both in buf and out buf are non zero Parameters out buf Output data buffer or NULL If NULL there will be no write transaction and MOSI pin will stay unchanged in_buf Input buffer to store read data or NULL If NULL there will be no read transaction and data on MISO pin will be ignored sz Transaction size ss_config Determines selection and operation of SS pin ss_config value must be created with macro SS CONF SS N SS MODE where SS_N is SS pin number and SS MODE is one of the following flags 2013 xdimax com rev 2 17 29 SUB 20 SUB 20 API SS_H SS goes high and stays high during and after transaction SS HL SS goes high and stays high during first byte transfer after that it goes low SS HHL SS goes high and stays high during first 2 bytes transfer after that it goes low SS HHHL SS goes high and stays high during first 3 bytes transfer after that it goes low SS HHHHL SS goes high and stays high during first 4 byte
18. SUB 20 User Manual Rev 2 17 O 2013 xdimax com SUB 20 Table of Contents Part I Part Il oa R N Part III 1 Document Revision History 5 SUB 20 Layout 6 GPIO Header cuina A ET 7 SPLHeader Nica ias 8 DB9 Connector incida diia 8 RS485 Connector sieurs ia owoc ida iii A aa a Hann A 9 Jumpers SWI SW2 ai a sg a ee ee 9 Power DiIStriD tiOn 3133552 sise nana raaa aa TY WASTE SD ADYA notons Nerea ist as te nse 10 SUB 20 API 13 Device Initialization 3 0 030 5 000000020 rennen ia nana Dan ana En nad a ner caso mecs mr ecese sata W GEL ceases 14 sub find devices ccoooncccnnnconcnnnsancnnnnanennnnnannnnas 14 SUD Open eee 14 sub_get_serial_number 15 sub get product Id nnesnnssnnnnnnnnnnnnnennnnnnennnnn 15 Sub_get_version nunnnsnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn 15 UN A 1 n AS 16 Internal EEPROM FunctiODS oncncnnnnnncncncncncnnnnononononononononnnnnnnnnononnnnnnnnnnnnnnnonono nano ann Raz az ARA R ARA ZA AAAA AAAA 16 sub_eep_read 16 sub_eep_write 16 126 fUNCtIONS iii didas 17 SUB si2C A A AE OO PA CS 18 SUD P CONFIG da 18 SUD LO ee kaa 19 sub_i2c_stop 19 SUD I2C SCAN ii RO RP ARA ciencia 19 SUD 126 NCA M O IIR OOO TAC 19 SUD 126 write nn 20 sub_i2c_hs_rw 21 ILEANA O ONENOTE 22 Bit bang 12G MaStelS cic esi sirio czna d ai 23 SUD DD 120 CONTO ii e ri added ka dain 23 SUD DD 1262 SCAN ii A a lianas 24 SUD DD 126 CA iii dd AA AAA r AAA AAA A
19. Slaves can hold the SCL line LOW to force the master into a wait state until the slave is ready Functions sub bb i2c config sub bb i2c scan sub bb i2c read sub bb i2c write 3 4 1 sub bb i2c config Synopsis int sub bb i2c config sub handle hndl int mode int stretch ms Configure SUB 20 Bit bang 12C Masters module Configuration is common for all Bit bang I2C channels Parameters mode Bit bang I2C Master mode One of the following flags BB I2C FAST P Fast Plus mode 1000KHz BB I2C FAST Fast mode 400KHz BB I2C STD Standard mode 100KHz stretch ms Clock stretching timeout up to 4194ms Clock stretching feature is available in Fast and Standard modes If SCL line is hold LOW by I2C slave device longer than stretch ms timeout Bit bang 12C function will fail and I2C Status will be set to OxEO 2013 xdimax com rev 2 17 24 SUB 20 SUB 20 API Return Value On success function returns 0 Otherwise error code Compatibility FW version 0 2 6 or grater Library version 0 1 12 16 or grater 3 4 2 sub bb i2c scan Synopsis int sub bb i2c scan sub handle hndl int channel int slave cnt char slave buf Scan I2C bus looking for connected slave devices Parameters channel Bit bang I2C Master channel 0 3 slave cent Buffer to store number of found slave devices slave buf Buffer to store found slave device addresses Return value On success function returns 0 Otherwise error code See
20. TUP Sample data on leading SCK edge setup on trailing See SPI Polarity and Phase SPI_SETUP_SMPL Setup data on leading SCK edge sample on trailing See SPI Polarity and Phase Below flags are relevant only for SPI master mode SPI_SLAVE not set SPI_LSB_FIRST Transmit LSB first SPI_MSB FIRST Transmit MSB first 2013 xdimax com rev 2 17 28 SUB 20 SUB 20 API PI_CLK_8MH SPI SCK frequency 8 MHz S SPI CLK 4MH SPI SCK freguency 4 MHz SPI CLK 2MH SPI SCK frequency 2 MHz SPI_CLK_1MH SPI SCK frequency 1 MHz S S S N NNN PI_CLK_500KHZ SPI SCK frequency 500 KHz PI_CLK_250KHZ SPI SCK frequency 250 KHz PI_CLK_125KHZ SPI SCK frequency 125 KHz Beginning from FW version 0 3 3 and library version 0 1 12 25 lower SPI frequencies down to 4KHz are supported for SPI Master transfer with sub spi transfer function Special SPI CLK HZ FHZ macro defined in libsub h where FHZ parameter denotes SPI frequency in Hz Supported frequencies range is 100 000Hz 4000Hz Exact frequency may differ from requested due to integer rounding in division SPI CLK HZ FHZ SPI SCK frequency 100 000Hz 4000Hz cfg_get Pointer to store current configuration read from SUB 20 device or NULL Return value On success function returns 0 Otherwise error code Example Read current SPI configuration sub_spi_config hndl 0 sspi config Configure SPI sub_spi_config hndl SPI ENABLE SPI CPOL RISE SPI SM
21. a 10 bit successive approximation ADC The ADC contains a Sample and Hold circuit which ensures that the input voltage to the ADC is held at a constant level during conversion Functions sub adc config sub adc single sub adc read 3 8 1 sub adc config Synopsis int sub adc config sub handle hndl int flags Configure SUB 20 ADC module Parameters flags set of below flags ADC ENABLE Enable ADC module If this flag is not set ADC module will be disabled ADC REF VCC Use VCC as ADC reference ADC REF 2 56 Use internal 2 56V reference Return value On success function returns 0 Otherwise error code 3 8 2 sub adc single See sub adc read 3 8 3 sub adc read Synopsis int sub adc single sub handle hndl int data int mux int sub adc read sub handle hndl int data int mux int reads Read single or multiple ADC conversion result s 2013 xdimax com rev 2 17 46 SUB 20 SUB 20 API Parameters data buffer to store conversion result s mux ADC input channel multiplexer control code s See table below reads number of results to read Differential Differential ADC mux code Single Ended Positive Neaaiua Gain ADC_SO ADC_S1 ADC_S2 ADC_S3 ADC_54 AMA ADC_S5 ADC_S6 ADC_S7 ADC_D10_10X ADC1 ADCO 10 ADC_D10_200X ADC_D32_10X ADC_D32_200X ADC D01 ADC D21 ADC D31 ADC D41 a ADC_D51 ae ADC_D61 NA ADC_D71 ADC D02 ADC D12 ADC D32 ADC D42 ADC D52 ADC 1 IV Inter
22. also Error Codes I2C Status Compatibility FW version 0 2 6 or grater Library version 0 1 12 16 or grater 3 4 3 sub bb i2c read Synopsis int sub bb i2c read sub handle hndl int channel int sa int ma int ma sz char buf int sz Perform complete I2C master read transaction with optional memory address write Transaction will have following format J8 SEJN Address Slave LACK LACK Memory Address Write Data Read If ma_sz is zero Memory Address Write stage will be skipped Function has no limitation of the read data size sz parameter However internal organization of the 12C slave device being read should be considered 2013 xdimax com rev 2 17 25 SUB 20 SUB 20 API Parameters channel Bit bang I2C Master channel 0 3 sa Slave Address ma Memory Address Will be shifted out in Memory Address Write stage MSB first ma_sz Memory Address size bytes buf Buffer to store read data sz Read data size bytes Return value On success function returns 0 Otherwise error code See also Error Codes 12C Status Compatibility FW version 0 2 6 or grater Library version 0 1 12 16 or grater 3 4 4 sub bb i2c write Synopsis int sub bb i2c write sub handle hndl int channel int sa int ma int ma sz char buf int sz Perform complete I2C master write transaction with optional memory address write Transaction will have following format J8 SEJN Add
23. amp edge_config Read Edge configuration EDGO 01B Any change EDG1 01B Any change EDG2 11B Risinge edge EDG7 EDG3 not detected rc sub_edge_config hndl 0x0035 0 set 0011 0101B See also Error Codes 3 7 7 2 sub_edge_read Synopsis int sub_edge_read sub_handle hndl int get int edge Read GPIO input status and EDGE status For GPIO Function reads logic value 1 high 0 Iow directly from GPIO pin For EDGE function reads 1 edge detected 0 edge not detected Parameters get Pointer to store received GPIO input status Bits 0 31 of get correspond to GPIOO GPIO31 input statuses edge Pointer to store EDGE status Bits 0 7 of edge correspond to EDG0 EDG7 Return value On success function returns 0 Otherwise error code See also 2013 xdimax com rev 2 17 41 SUB 20 SUB 20 API Error Codes 3 7 8 Fast PWM Fast PWM outputs are available on SPI header pins 4 6 8 see SPI Header Outputs are referenced as FPWM_0 FPWM_1 and FPWM_2 All three outputs share the same PWM generation module in SUB 20 and have the same PWM frequency but separate duty cycle configuration Duty Duty Cycle Cycle PWM Period Fast PWM frequency range is 8Mhz 0 238Hz Duty cycle precision is 2 16 bits depending on the PWM frequency Functions sub fpwm config sub fpwm set 2013 xdimax com rev 2 17 42 SUB 20 SUB 2
24. ansmitted NAK received Data byte transmitted ACK received Data byte transmitted NAK received Arbitration lost in SLA or NAK received SLA R transmitted ACK received SLA R transmitted NAK received Data received ACK has been returned Data received NAK has been returned Arbitration lost Arbitration lost in START Arbitration lost in STOP Arbitration lost in read ACK Arbitration lost in read NAK Arbitration lost in write Unknown error 2013 xdimax com rev 2 17 23 SUB 20 SUB 20 API OxFF Illegal START or STOP condition 3 4 Bit bang I2C Masters Beginning from the FW version 0 2 6 and library version 0 1 12 16 SUB 20 provides additional four independent I2C master channels on GPIO24 31 compatible with I2C specification 3 0 Header Pin GPIO Alternative I2C Master Function 16 GPIO31 Each channel can operate in Fast Plus 1000KHz Fast 400KHz and Standard 100KHz modes In Fast and Standard modes I2C masters support clock stretching SDAx SCLx Pull ups Considering the fact that bit bang I2C channels share the GPIO pins with other SUB 20 modules there are no internal mounted on SUB 20 board pull ups on these channels Pull ups must be provided on target board Clock Stretching In Fast and Standard modes bit bang 12C masters support clock stretching Clock stretching pauses a transaciion by holding the SCL line LOW The transaction cannot continue until the line is released HIGH again
25. ause 45 Clause 22 MDIO frame format PREAMBLE PHVAD REGAD TA DATA READ 111 111 01 AAAAA RRRRR zo DDDDDDDDDDDDDDDD WRITE 111 111 01 AAAAA RRRRR 10 DDDDDDDDDDDDDDDD Clause 45 MDIO frame format PREAMBLE ST OP PRTAD DEVAD ra ADORESS DATA Addres aaa 00 00 PPPPP EEEEE 10 AAAAAAAAAAAAAAAA wae 111111 00 01 PPPPP eeeee 10 DDDDDDDODODDDDDD Read 111 111 00 11 _PPPPP_ _EEEEE_ zo DDODDODDODDDDODO Poste 111 111 00 10 PPPPP EEEBE zo DDDDDDODDDDDDDDD read increment address Channels Beginning from FW version 0 2 8 and library version 0 1 12 18 additional MDIO1 channel is available on SPI header see SPI Header To access MDIO1 channel use sub mdio xfer ex function with channel 1 CFP MSA Support Beginnig from FW version 0 3 2 and library version 0 1 12 24 SUB 20 supports CFP MSA compatible transactions at 4MHz MDC frequency See sub mdio xfer ex Functions sub mdio22 sub mdio45 sub mdio xfer sub mdio xfer ex 2013 xdimax com rev 2 17 33 SUB 20 SUB 20 API 3 6 1 sub mdio22 Synopsis int sub mdio22 sub handle hndl int op int phyad int regad int data int content Generate IEEE 802 3 Clause 22 MDIO READ or WRITE frame Frame format is shown here Clause 22 MDIO frame Parameters op operation code SUB MDIO22 READ READ operation SUB MDI022 WRITE WRITE operation phyad 5 bit PHY address regad
26. bility FW version 0 2 7 or grater Library version 0 1 12 17 or grater 3 7 5 sub_gpiob_read Synopsis int sub_gpiob_read sub_handle hndl int get Read GPIOB input status Function reads logic value 1 high 0 low directly from GPIOB pin Parameters get Pointer to store received GPIOB input status Bits 0 7 of get correspond to GPIOBO GPIOB7 input statuses Return value On success function returns 0 Otherwise error code See also Error Codes 2013 xdimax com rev 2 17 39 SUB 20 SUB 20 API Compatibility FW version 0 2 7 or grater Library version 0 1 12 17 or grater 3 7 6 sub_gpiob write Synopsis int sub_gpiob_write sub_handle hndl int set int get int mask Set GPIOB output status For GPIOB in output state function will set output driver to drive 1 high O low For GPIO in input state function will 1 enable 0 disable weak pull up on corresponding GPIOB pin Parameters set Bits 0 7 of set parameter correspond to GPIOBO GPIOB7 output statuses get Pointer to store current GPIOB output status read from SUB 20 mask Bit in set parameter will take effect only if corresponding mask bit is 1 With mask 0 function will only read current GPIOB output status Return value On success function returns 0 Otherwise error code See also Error Codes Compatibility FW version 0 2 7 or grater Library version 0 1 12 17 or grater 3 7 7 Edge Detector Edge Detector descriptio
27. dule to FIFO with sub fifo config FIFO_SELECT_SPI must be set If required write data to FIFO with sub fifo write This data will be read by external SPI master If required read data from FIFO with sub fifo read This will be data written by external SPI master Example Below is an example to exchange 12 bytes with SPI master sub_spi_config hndl SPI_ENABLE SPI_SLAVE SPI_CPOL_RISE SPI_SMPL_SETUP 0 sub_fifo_config hndl FIFO_SELECT_SPI sub_fifo_write hndl Hello Master 12 100 read_sz 0 while read_sz lt 12 rc sub fifo read hndl in buff 64 10000 wait 10 sec Le re lt O return rc error read_sz rc Slave Select SUB 20 SPI Slave module use SSO pin as slave select SSO must be pulled low by external SPI master to enable SUB 20 SPI module functionality When SSO is held low the SPI is activated and MISO becomes an output All other pins are inputs When SS is driven high all pins are inputs and the SPI is passive 2013 xdimax com rev 2 17 54 SUB 20 SUB 20 API 3 11 3 12C Slave Configuration To use SUB 20 in 12C slave mode following should be done Configure I2C Slave module with sub i2c config Set desired I2C slave address and optional flag s Connect I2C Slave module to FIFO with sub fifo config Set FIFO SELECT I2C flag If required write data to FIFO with sub fifo write This data will be read by external I2C master
28. f gt 0 printf Serial Number s n buf else JE Enver 3 1 4 sub get product id Synopsis int sub get product id sub handle hndl char buf int sz Get product ID string descriptor Parameters buf buffer to store descriptor sz buffer size Return value On success function returns string descriptor size Otherwise negative number Example if sub get product id hndl buf sizeof buf gt 0 printf Product ID s n buf else JE Error 7 3 1 5 sub get version Synopsis const struct sub version sub get version sub handle hndl 2013 xdimax com rev 2 17 16 SUB 20 SUB 20 API Get version of shared DLL or static library driver SUB 20 device and bootloader Return value Function fills internal structure with gathered versions and returns pointer to this structure Example const struct sub_version sub_ver sub_ver sub_get_version hndl 3 1 6 sub reset Synopsis int sub_reset sub handle hndl Reset SUB 20 device Return value On success function returns 0 Otherwise error code 3 2 Internal EEPROM Functions Beginning from the firmware version 0 8 4 and library version 0 1 12 26 SUB 20 provides access to it s internal EEPROM non volatile memory EEPROM memory array size is 1KB endurance 100 000 Write Erase Cycles EEPROM Memory array can be freely used by application without any format or interdependency rest
29. fo_read Synopsis int sub_fifo_read sub_handle hndl char buf int sz int to_ms Function attempts to read sz bytes from IN FIFO into buffer in no more then to_ms time Parameters buf destination buffer 2013 xdimax com rev 2 17 53 SUB 20 SUB 20 API sz buffer size Considering internal FIFO structure it is highly recommended to use only 64 divisible sz values and corresponding buffer size It will guarantee better performance and no buffer overflow error EFBIG to_ms timeout in milliseconds Return Value On success a non negative number of actually read bytes is returned It can be less then or equal to sz In case of error negative error code defined in errno h will be returned and if applicable sub_errno will be set to the corresponding value Possible error codes are ENOENT 2 USB failure EIO 5 USB failure ENOMEM 12 Memory failure EINVAL 22 Invalid parameter EFBIG 27 Buffer overflow To prevent this error use 64 divisible sz ETIMEDOUT 116 Timeout Known Issue If IN FIFO contains exactly 64 or 128 bytes attempt to read more then 64 or 128 bytes correspondingly with sub_fifo_read will cause to timeout 116 As a workaround always call sub_fifo_read with sz 64 3 11 2 SPI Slave Configuration To use SUB 20 in SPI slave mode following should be done Configure SPI module with sub spi config Make sure to set SPI SLAVE flag Connect SPI mo
30. htly differ from the desired as actual baudrate is an integer quotient from dividing the 16MHz reference clock Return value On success function returns 0 Otherwise error code Example Set 9660 bps 8 data bits no parity 1 stop bit sub_rs_set_config hndl RS_RX_ENABLE RS_TX_ENABLE RS_CHAR_8 RS_PARITY_NONE RS_STOP_1 9600 3 10 2 sub_rs_get_config Synopsis int sub_rs_get_config sub_handle hndl int config int baud Read current SUB 20 UART configuration Parameters config will be filled with UART configuration see sub rs set config for details baud will be filled with actual UART baudrate Return value On success function returns 0 Otherwise error code 3 10 3 sub_rs_timing Synopsis int sub_rs_timing sub_handle hndl int flags int tx_space_us int rx msg us int rx byte us Configure UART transfer timing and order of transmit and receive operations Actual transfer is initiated by sub rx xfer function Parameters flags one or none of the below flags RS RX BEFORE TX Receive message and after that transmit message RS RX AFTER TX Transmit message and after that receive message none Receive and transmit simultaneously tx space us delay in us between subseguent byte transmit rx MSg Us message reception timeout in us rx byte us byte to byte reception timeout in us Delay and timeouts precision is 64 us They should not exceed 4 000 000us 4s Following table exp
31. imitation of the read data size sz parameter However internal organization of the 12C slave device being read should be considered Parameters sa Slave Address ma Memory Address Will be shifted out in Memory Address Write stage MSB first ma_sz Memory Address size bytes buf Buffer to store read data sz Read data size bytes Return value On success function returns 0 Otherwise error code See also Error Codes 12C Status 3 3 7 sub i2c write Synopsis int sub i2c write sub handle hndl int sa int ma int ma Sz char buf int sz Perform complete I2C master write transaction with optional memory address write Transaction will have following format J8 SEJN Slave Memory Address Write Data Write If ma_sz is zero Memory Address Write stage will be skipped Function has no limitation of the write data size sz parameter However internal organization of the I2C slave device being written should be considered especially Acknowledge Polling and EEPROM Page Write Parameters 2013 xdimax com rev 2 17 21 SUB 20 SUB 20 API sa Slave Address ma Memory Address Will be shifted out in Memory Address Write stage MSB first ma_sz Memory Address size bytes buf Buffer for data to be written sz Write data size bytes Return value On success function returns 0 Otherwise error code See also Error Codes I2C Status 3 3 8 sub i2c hs rw Synopsis int sub i2c hs rw
32. lains relation between rx msg us and rx byte us parameters rx msg us 0 rx byte us 0 Message reception will last no more then 4s rx msg us 0 rx byte us gt 0 First byte reception will last no more then 4s Every next byte should be received in rx byte us time rx msg us gt 0 rx byte us 0 Message reception will last no more then rx msg us time 2013 xdimax com rev 2 17 50 SUB 20 SUB 20 API rx_msg_us gt 0 rx byte us gt 0 First byte reception will last no more then rx msg us time Every next byte should be received in rx_byte_us time Return value On success function returns 0 Otherwise error code Example Request message transmit and after that receipt No space between transmitted bytes Message should be received in 1s sub_rs_timing hndl RS_RX_AFTER_TX 0 1000000 0 3 10 4 sub_rs_xfer Synopsis int sub rs xfer sub handle hndl char tx buf int tx sz char rx buf int rx sz Transmit and or receive message s via UART configured with sub rs set config and in accordance with transfer timing set with sub rs timing Parameters tx_buf buffer with data to be transmitted tx_sz number of bytes to transmit can be 0 if transmit not required rx_buf buffer to store received data rx_sz maximal number of bytes to receive can be O if reception is not required rx_sz and tx_sz should not be grater then 62 bytes Function will terminate after following conditions fulfilled t
33. lave Functions 2013 xdimax com rev 2 17 18 SUB 20 SUB 20 API sub i2c freg sub i2c config sub i2c start sub i2c stop sub i2c read sub i2c write sub i2c hs rw 3 3 1 sub i2c freq Synopsis int sub i2c freg sub handle hndl int freq Set and get SUB 20 I2C master clock frequency If freq is non zero 12C clock frequency will be set to value equal or close to freq SUB 20 has 12C frequency generator that can generate clock frequencies in range form 444 444 KHz down to 489 Hz Function will calculate close possible frequency from the available range If function succeed freq will reflect the resulting 12C clock frequency Some of available I2C clock frequencies are listed below 444444 Hz Maximal 421052 Hz 400000 Hz 100000 Hz 491 Hz 489 Hz Minimal Parameters freq Desired frequency or zero On return will be filled with resulting frequency Return value On success function returns 0 Otherwise error code 3 3 2 sub i2c config Synopsis int sub_i2c_config sub handle hndl int sa int flags Configure SUB 20 I2C module Parameters sa slave address for SUB 20 in I2C slave mode See 12C Slave Address Convention and I2C Slave flags set of below flags I2C_GCE Enable general call address 0x00 detection in I2C slave mode I2C_DISABLE Disable I2C module Any following I2C transaction will enable I2C module I2C_DISABLE is required to get full control over GPIO8 GPIO9 I Os While 1
34. n SUB 20 Edge detector module EDGE is capable to detect falling rising or any change edge on the GPIO pins listed below GPIO Header Pin GPIO Edge Number EDGO 2 3 4 EDG5 13 E 14 15 E 16 Pulses on EDG7 0 pins wider than the minimum pulse width of 50ns will trigger edge detection If enabled the edge detection will trigger even if the corresponding GPIO are configured as outputs Functions sub edge config sub edge read 2013 xdimax com rev 2 17 40 SUB 20 SUB 20 API 3 7 7 1 sub edge config Synopsis int sub_edge_config sub_handle hndl int set int get Configure EDGE module Parameters set set will be used only if get 0 EDGE lines EDG7 EDGO are configured by two bits Ex1 Ex0 in set where x is 7 0 set bits have following interpretation MSB 1 16 15 14 13 12 11 10 og 08 07 06 os 04 03 o2 o1 oo EDG7 EDG6 EDG5 EDG4 EDG3 EDG2 EDG EDGO E71 E70 E61 Eso E51 E50 E41 E40 E31 Eso E21 E20 E11 E10 E01 E00 Ext Ex0 Edge Detection 0 0 No gt O 1 Anychange O Falingedge 1 1 Risingedge get Pointer to store current edge configuration read from SUB 20 If get is not zero function will read edge configuration otherwise it will set edge configuration Return value On success function returns 0 Otherwise error code Example rc sub_edge_config hndl 0
35. nal 1 1V NA ADC_GND ADC Result For single ended conversion nr 1023 7 VREF AL ADC For differential Vonps Vyrc GAIN 512 BOS DZ gt gt VREF ADC is a result of conversion Note that the result of differential conversion is signed and can be negative Return value On success function returns 0 Otherwise error code Example int adc adc_buf 3 adc mux 3 i r 2013 xdimax com rev 2 17 47 SUB 20 SUB 20 API sub_adc_single fd amp adc ADC S0 Read ADC on ADCO input adc mux 0 ADC S0 adc mux 1 ADC S2 adc mux 2 ADC S3 sub adc read fd adc buf adc mux 3 Read ADC on ADC0 2 3 inputs 3 9 LCD Functions Functions sub lcd write 3 9 1 sub Icd write Synopsis int sub lcd write sub handle hndl char str This function will work only on SUB 20 configurations with LCD Characters from str are written to the LCD beginning from the current LCD position Special characters and seguences listed below are used to format LCD output and control current position ANSI C notation Hex value Description Example f loxoc Clear LCD and go to first position fHello ir 0x0D Go to first position n Go to next string exY 0x1B X Y Go to position X Y Every string written to LCD will be space padded till the end of the string Parameters str LCD string Return value On success function returns 0 If LCD is not supported function will
36. ndition followed by the device slave address and R W bit Only if the internal write cycle has completed will the EEPROM respond with an ACK allowing the read or write sequence to continue Acknowledge polling should be performed on application level SUB 20 knows nothing about nature of I2C slave device it is connected to EEPROM Page Write 12C EEPROMs are usually capable of no more then 64 byte page writes The internal EEPROM data address lower 6 bits are internally incremented following the receipt of each data byte The higher data address bits are not incremented retaining the memory page row location When the data address internally generated reaches the page boundary the following byte is placed at the beginning of the same page If more than 64 data bytes are transmitted to the EEPROM the data address will roll over and previous data will be overwritten The address roll over during write is from the last byte of the current page to the first byte of the same page High Speed Support Beginning from FW version 0 3 2 and library version 0 1 12 24 SUB 20 provides High Speed HS I2C Master capabilities compliant to I2C Bus Specification Rev 3 0 HS I2C Master functionality is available via sub i2c hs rw API call Timing characteristics can be found here HS 12C Master AC Characteristics Slave Mode SUB 20 can work in both I2C master and I2C slave modes Detailed description of I2C slave mode can be found here SUB 20 as 12C S
37. ne Se ee Rene et Le 48 K o KO co a a 49 SUDIFSS MING AAA O 49 UN VR AOI anna aan E a nahen d nr der tan are een 50 11 FIFO Streaming Slave Modes ennnsreesremnsnennnes 51 FIFO Functions ss nasaeae nawannowe RARA 51 sub_fifo_config 52 SUD AO WITE naar ann AAA AA ir LEAL AL OR 52 SUD filo 151210 PRO OP tate hy Senate E TOO O ren COP ep re ee DOLE 52 SPI Slave 12C Slave 12 Error Codes SUP C p a lo E EE A E E AA AA AA AAA A AT 54 SUD SECO iii dada 55 Part IV Electrical Characteristics 56 1 Absolute Maximum RatingS aaa eee aaa ema zaawan e cr 56 2 DC CharacterisSticS ini arar diia da a ah anna an A AR dc 56 3 AG Characteristics iii da 56 Part V Ordering Information 57 O 2013 xdimax com SUB 20 O 2013 xdimax com 5 SUB 20 Document Revision History 1 Document Revision History 2 17 Fixed Power Distribution Picture 2 16 Sub reset Updated Error Codes N 2 15 EEPROM Read Write Functions 2 14 SPI CLK XXXXX SUP 20 Dxxx picture ND 2 13 Added Power Distribution topic 2 12 High Speed 12C Master CFP MSA Support DD 2 11 Edge Detector 2 10 2C_DISABLE 2 9 sub spi transfer ess 2 8 GPIOB FIFO READ FULL MDIO1 D 2 7 Bit bang 12C Masters Updated GPIO Header for 12Cx SPIx UARTx DB 2013 xdimax com
38. on like one shown below 1 SS changes according to ss config parameter 2 out sz bytes are transmitted via MOSI MOSI will be in output state during transfer 3 MOSI state is changed to HiZ after last bit transmitted If required SS changes 4 in sz bytes received from MISO input MOSI left in HiZ state 5 SS changes according to ss config parameter 2013 xdimax com rev 2 17 31 SUB 20 SUB 20 API SPI Clock SCK phase and polarity can be configured with sub spi config Above implementation of SPI transaction allows using of the SUB 20 as 3 Wire SPI master In this case connection to 3 Wire device should be as following Parameters out_buf Output data buffer in_buf Input buffer to store read data out_sz Number of bytes to transmit in range 0 60 in_sz Number of bytes to receive in range 0 60 ss_config Determines selection and operation of SS pin ss_config value must be created with macro SS_CONF SS_N SS_MODE where SS_N is SS pin number and SS_MODE is one of the following flags SS_HL SS goes high and stays high during transmit stage after that it goes low SS_HI SS goes high and stays high during eniire transaction transmit and receive after that it goes low SS_LH SS goes low and stays low during transmit stage after that it goes high SS_LO SS goes low and stays low during entire transaction transmit and receive after that it goes high SS HiZ SS stays in HiZ mode Except SS0
39. ot exceed 100 mA The sum of all lou for GPIO0 GPIO3 GPIO8 GPIO15 should not exceed 100 mA The sum of all lou for GPIO24 GPIO31 should not exceed 100 mA The sum of all lou for GPIO16 GPIO23 should not exceed 100 mA OUR Gores SR 4 3 AC Characteristics Symbol Parameter Condition Min Typ Max Units AE gt A SPI Fspi SPI Master frequency______ __________ otws 8 Mkz FspLsLave SPI Slave frequency N 2 vee MDIO DO A y O F me MDC freauency ______ N 1 1 MHz High Speed HS I2C Master FsciH_ HSSCL frequency 1 183125 M tow HS SCL LOW period FP ies tHHiGH HS SCL HIGH period CS BAL SE EG 2013 xdimax com rev 2 17 57 SUB 20 Ordering Information 5 Ordering Information Geh padku la SUB 20 B Basic V v v v rn 20 EB Basic Enclosure Heavy duty enclosure with DB9 Connector m Heavy duty enclosure with vi DB9 and DB26 ISUB 20 V Visual V v v v v ISUB 20 R25 Serial2 V V v v v v ISUB 20 R45 Serial4 V V v v v v SUB 20 15 Infra5 V v v vw v V SUBz01o_ fv vv a Custom Configuration For SUB 20 Lxxx xxx can be any of the above configuration with addition of SPI Level Converters and without SPI Slave option For example SUB 20 LV is SUB 20 V board with SPI Level Converters SUB 20 B SUB 20 V SUB 20 R25 SUB 20 R45 SUB 20 LB SU
40. ress Slave LACK LACK Memory Address Write Data Write If ma_sz is zero Memory Address Write stage will be skipped Function has no limitation of the write data size sz parameter However internal organization of the I2C slave device being written should be considered especially Acknowledge Polling and EEPROM Page Write Parameters channel Bit bang I2C Master channel 0 3 sa Slave Address ma Memory Address Will be shifted out in Memory Address Write stage MSB first ma_sz Memory Address size bytes buf Buffer for data to be written sz Write data size bytes Return value On success function returns 0 Otherwise error code See also 2013 xdimax com rev 2 17 26 SUB 20 SUB 20 API Error Codes 12C Status Compatibility FW version 0 2 6 or grater Library version 0 1 12 16 or grater 3 5 SPI Functions SPI Pins Configuration After SPI is enabled SUB 20 SPI module will take control over SPI pins Pin Function Master mode Slave mode Disabled SCK SPI Master Clock MOSI Master Out Slave In MISO Master In Slave Out Output SSO Slave Select 0 Output Hi Configurable by sub_spi_transfer gt HiZ SS3 Slave Select 1 4 Configurable by Not in use SS4 sub spi transfer If SPI is disabled all SPI pins are in HiZ In SPI slave mode MISO is output only when SSO is low SPI SCK Polarity and Phase explanations SPI Transfer format with SPI SMPL SETUP SPI_CPOL RISE
41. return Feature not supported Example sub lcd write hndl fHello nWorld sub_lcd_write hndl f e20Hello e21World sub lcd write bndl rl n2 sub lcd write hndl N T NnR sub lcd write hndl e20abc e2ldef Compatibility Required firmware version gt 0 0 4 2013 xdimax com rev 2 17 48 SUB 20 SUB 20 API Required DLL version gt 0 1 12 2 3 10 RS232 RS485 Functions RS232 RS485 Frame format Pe I 21314 8 00000 SATA A IDLE St IDLE St Start bit always low n Data bits 0 to 8 P Parity bit Can be odd or even Sp Stop bit always high Functions sub rs set config sub rs get config sub rs timing sub rx xfer 3 10 1 sub rs set config Synopsis int sub rs set config sub handle hndl int config int baud Configure SUB 20 UART Universal Asynchronous Receiver Transmitter Parameters config UART configuration Config should be assembled as a combination of the following flags RS RX ENABLE Enable UART receiver RS TX ENABLE Enable UART transmitter RS CHAR 5 RS CHAR 6 RS CHAR 7 Data Bits RS CHAR 8 RS CHAR 9 RS PARITY NONE RS PARITY EVEN Parity RS PARITY ODD RS STOP 1 l RS STOP 2 Stop Bits To disable UART provide configuration without RS_RX_ENABLE and RS_TX_ENABLE 2013 xdimax com rev 2 17 49 SUB 20 SUB 20 API baud Desired baudrate Maximum baudrate is 2Mbps The actual baudrate may slig
42. rev 2 17 SUB 20 Layout 6 SUB 20 2 SUB 20 Layout GPIO J7 2013 xdimax com rev 2 17 SUB 20 SUB 20 Layout 2 1 GPIO Header Header Pin 28 29 30 31 32 33 34 GPIO Alternative Function Notes Gpioi GPS 1 O GPioig G y O GPiois TO GPIO24 emo scuxo mtsoxot GPIO25 pwm_1 spaxo mosrxo IA GPIO26 em 2 sc x1 sckx0 PO GPIO27 pwa_3 spax1 ssx0 PO GPIO28 pwm_4 scLx2 mrsoxi UARTxO RX Cid GPIO29 pwm_s spax2 mostxi mm rx GPIO30 ewm_6 scLx3 sckx1 UARTZLRX GPIO31 pum 7 spax3 ssx11 UARTXI rx LCD_DO For Configurations with LCD IR_TX For Configurations with IR Er For Configurations with LCD LCD_RS MATI ECS O HI ADC6 elo DCS GPIO20 HAITI tC ADC2 OOOO MAITE ADCO OOOO GND 1 Under development 2013 xdimax com rev 2 17 8 SUB 20 SUB 20 Layout 2 2 SPI Header 2 10 SPI J6 1 9 Header Pin SPI Function Fast GPIOB MDIO1 Notes 1 MDC1 Optional Level Converter 2 GPIO Voltage 3 Optional Level Converter 4 GPIO Voltage 5 Output Optional Level Converter e lss i FPwm1lePioBa4 GPIO Voltage 7 CK Master Clock GPIOB7 MDIO1 Optional Level Converter 8 SS4 0 _ FpwM_2 GPIOBG6 GPIO Voltage 9 SPI_EXT_PWR External SPI EXT_PWR Power 0 GND en D Level Converter Adju
43. rictions Access to EEPROM is gained by two simple functions sub eep read sub eep write 3 2 1 sub eep read Synopsis int sub eep read sub handle hndl int addr char buf int sz Read sz bytes from internal EEPROM starting from address addr Read data will be stored in buf Parameters addr read start address buf buffer to store read data sz read size max 64 bytes Return value On success function returns 0 Otherwise error code 3 2 2 sub_eep_write Synopsis int sub eep write sub handle hndl int addr char buf int sz Write sz bytes into internal EEPROM starting from address addr Write data is taken from buf 2013 xdimax com rev 2 17 17 SUB 20 SUB 20 API Parameters addr write start address buf buffer for data to be written sz write size max 64 bytes Return value On success function returns 0 Otherwise error code 3 3 12C functions Slave Address Convention Slave address parameter referenced in 12C related functions is 7 bit number representing 12C slave device address without R W bit For example with slave address parameter equal 0x50 slave address stage of the 12C transaction will look like Slave Address 0x50 1010000 y Acknowledge Polling 12C EEPROM slave devices may enter internal memory write cycle Once the internally timed write cycle has started EEPROM inputs are disabled acknowledge polling can be initiated This involves sending a start co
44. rs out buf Output data buffer or NULL If NULL there will be no write transaction and MOSI pin will stay unchanged in buf Input buffer to store read data or NULL If NULL there will be no read transaction and data on MISO pin will be ignored sz Transaction size ess str string defining SS selection and activity during SPI transfer Characters of the ess str have following meaning Select SS0 Select SS1 Select SS2 Select SS3 Select SS4 SS High IRODV O Byte Transfer 2013 xdimax com rev 2 17 30 SUB 20 SUB 20 API L SS Low Byte Transfer N SS High No Byte Transfer v SS Low No Byte Transfer Small delay without SS changes No Byte Transfer Return value On success function returns 0 Otherwise error code Example Write 5 bytes with SSO Low Make SSO High to Low pulse after each byte rc sub spi transfer hndl out 0 5 OL vL vL vL vL v Transfer 10 bytes with SS High Use SS1 for first 5 bytes and SS2 for last rc sub spi transfer hndl out in 10 1HHHHHv 2HHHHHv Read 10 bytes SSO High for first 2 bytes and low after that rc sub spi transfer hndl 0 in 10 OHHv Compatibility FW version 0 2 9 or grater Library version 0 1 12 19 or grater 3 5 4 sub sdio transfer Synopsis int sub sdio transfer sub handle hndl char out buf char in buf int out sz int in sz int ss config Perform 3 Wire compatible SPI master transacti
45. s transfer after that it goes low SS HI SS goes high and stays high during entire transfer after that it goes low SS L SS goes low and stays low during and after transaction SS LH SS goes low and stays low during first byte transfer after that it goes high SS LLH SS goes low and stays low during first 2 bytes transfer after that it goes high SS LLLH SS goes low and stays low during first 3 bytes transfer after that it goes high SS LLLLH SS goes low and stays low during first 4 bytes transfer after that it goes high SS LO SS goes low and stays low during entire transfer after that it goes high SS HiZ SS stays in HiZ mode Except SS0 If ss config is zero there will be no SS activity changes Return value On success function returns 0 Otherwise error code Example Write 10 bytes Use SSO low rc sub spi transfer hndl out 0 10 SS CONF 0 SS LO Transfer 10 bytes out and 10 bytes in Use SS2 high rc sub spi transfer hndl out in 10 SS CONF 2 SS HI Read 10 bytes No SS rc sub_spi_transfer hndl 0 in 10 0 3 5 3 Synopsis int sub spi transfer ess sub handle hndl char out buf char in buf int sz char ess str sub spi transfer ess Perform SPI master transaction with Extended Slave Select control ESS Depending on out buf and in buf parameters transaction can be either read out buf 0 write in buf 0 or read write both in buf and out buf are non zero Paramete
46. s used to rout SPI MDIO1 signals to SPI header and DB9 connector SPI MDIO1 voltage in this case is defined by CPU Voltage 2013 xdimax com rev 2 17 13 SUB 20 SUB 20 API 3 SUB 20 API API Functions List sub find devices sub_open sub get serial number sub get product id sub get version sub eep read sub eep write sub i2c freg sub i2c config sub i2c start sub i2c stop sub i2c scan sub i2c read sub i2c write sub bb i2c config sub bb i2c scan sub bb i2c read sub bb i2c write sub spi config sub spi transfer sub gpio config sub gpio read sub _gpio write sub gpiob config sub gpiob read sub gpiob write sub edge config sub edge read sub fpwm config sub fpwm set sub adc config sub adc read sub adc single sub Icd write sub rs set config sub rs get config sub rs timing sub rs xfer sub fifo config sub fifo read sub fifo write 2013 xdimax com rev 2 17 14 SUB 20 SUB 20 API 3 1 Device Initialization Functions sub find devices sub open sub get serial number sub get product id 3 1 1 sub find devices Synopsis sub device sub find devices sub device first Function scans USB devices currently connected to the host looking for SUB 20 device s If parameter first is NULL function will initiate new search otherwise it will continue to search from the place it finished during last call Return value Function returns next found SUB
47. sa Slave Address r_w O write 1 read sz size in bytes of data to read write act_sz actual read write size This parameter will be filled by function data 64 bytes data buffer For read transaction function will attempt to read sz bytes into buffer for write transaction function will attempt to write sz bytes from buffer Maximal transaction size is 64 bytes status 12C transaction result see I2C Status Return value On success function returns 0 Otherwise error code The I2C Error return value means that there was a failure at the master code transmit stage Results of the HS transactions are reported in status field of the corresponding transaction descriptor Example Master Code 00001001 Write 4 bytes to slave 0x44 Write 2 bytes to slave 0x50 Read 8 bytes from slave 0x44 S struct sub i2c hs xfer xfer 3 EC 3 3 9 0 44 0 4 0 MAx10 x11 x12 x13 t 0850 0 2 0 Nxz0NxS0 0 F 1 0x44 1 8 0 0 sub_i2c_hs_rw hndl 0x01 3 xfer 12C Status The status of last I2C operation successful or not successful is stored in sub i2c status global variable defined in libsub h as extern int sub_i2c_status Following statuses are available 0x00 0x08 0x10 0x18 0x20 0x28 0x30 0x38 0x40 0x48 0x50 0x58 OxE0 0xE1 OxE2 OxE3 OxE4 OxE5 OxF8 No errors START condition transmitted Repeated START condition transmitted SLA W transmitted ACK received SLA W tr
48. stable operating voltage in configurations with Level Converters see Jumpers and Ordering Information GPIO Voltage Operates at the same voltage as GPIO according to SUB 20 configuration see Ordering Information 2 3 DB9 Connector Pin Function Configuration 1 PI SSO 2 I2C EXT PWR O RS232 PC_RX 3 SPI EXT_PWR 2013 xdimax com rev 2 17 9 SUB 20 SUB 20 Layout RS232 PC TX Serial2 PI SCK GND 2C SDA O PI MISO O O C SCL PI MOSI Pin Function A inverting or pin B non inverting or pin 2 5 Jumpers SW1 SW2 J7 5V 3 3V SW2 swi Li j 3 JE O 1 m 123456 2013 xdimax com rev 2 17 10 SUB 20 SUB 20 Layout 12C Pull ups Voltage when JP2 1 2 closed 12C Pull ups Voltage SCL Pull up SDA Pull up J7 88V lt MiS not be used with 3 3V configurations nem Kia not be used in Serial configurations 5V of n V D IND e E o 3 External J6 9 Only for Lxxx configurations SE volage 2 3 or DB9 3 DB9 3 Can not be used as SPI Voltage in Serial configurations Closed a Force Bootloader on Power Reset or Pressed Force Monitor on Power Reset Pressed Only for Serial2 configurations For additional information about SUB 20 configurations please see Ordering Information SPI Voltage when JP6 1 2 closed NP P P lt DIOD ORDO N 2 6 Power Dis
49. tribution The diagram below shows SUB 20 power distribution and voltage levels 2013 xdimax com rev 2 17 11 SUB 20 SUB 20 Layout Vcc CPU GPIO CPU and GPIO Voltage CPU and GPIO voltage is defined by J7 lt can be 5V from the USB or 3 3V from the internal regulator In customized SUB 20 models 3 3V regulator can be exchanged with 2 7V 5V regulator It is possible to source up to 70mA from GPIO33 to power external target 12C Voltage 12C voltage is defined by 12C pull ups voltage If pull ups are enabled with JP3 JP4 12C voltage is controlled by JP2 It can be internal 5V or 3 3V or external taken from DB9 2 External 12C voltage is not available in SUB 20 R25 Serial2 model SPI MDIO1 Voltage SPI Level Converter and RN1 resistors network are mutually exclusive SPI Level Converter is available in SUB 20 Lxxx models If SPI Level Converter installed SPI MDIO1 voltage is defined by JP5 and JP6 It can be 5V or 3 3V if JP6 is configured for internal voltage or externally referenced if JP6 is configured for external voltage External 2013 xdimax com rev 2 17 12 SUB 20 SUB 20 Layout voltage can be taken from SPI 9 or DB9 3 in non Serial2 model External voltage reference can be in range 1 6V 5V for SUB 20 Lxxx models or 1 2V 3 3V for SUB 20 Lxxx 1 2 models Models with SPI Level Converter can not be used in SPI Slave mode If SPI Level converter is not installed RN1 i
50. umber Return Value Function returns pointer to string with error description If error number is unknown function will return pointer to string Unrecognized error lt error_number gt 2013 xdimax com rev 2 17 56 SUB 20 Electrical Characteristics 4 Electrical Characteristics 4 1 Absolute Maximum Ratings Operating Temperature 20 C to 65 Voltage on any Pin with respect to Ground 0 5V to VCC 0 5V Maximum Operating Voltage 6V DC Current per I O Pin 40mA DC Current Vcc and GND Pins 200mA 4 2 DC Characteristics Symbol EE ET m YE UE mm Low Voltage 3 3V 5 5V CE CE LN Input High Voltage Vcc 3 3V 5 5V 0 6Voc Vo 05 V loe 5MA Vcc 3 3V 0 2 0 5 lOH 10mA Vcc 3 3V 2 Pe 2 6 Tet Leakage Guan VO Fi Wars BVB TA ice Power Consumption Current jVe 6V Bo m Although each I O port can sink or source more than the test conditions under steady state conditions non transient the following must be observed The sum of all lot for GPIO4 GPIO7 should not exceed 100 mA The sum of all lot for GPIO0 GPIO3 GPIO8 GPIO15 should not exceed 100 mA The sum of all lot for GPIO24 GPIO31 should not exceed 100 mA The sum of all lot for GPIO16 GPIO23 should not exceed 100 mA If lo exceeds the test condition Vo may exceed the related specification Pins are not guaranteed to sink current greater than the listed test condition The sum of all lou for GPIO4 GPIO7 should n
51. vel Converter to prevent short circuit on this pins Functions sub gpio config sub gpio read sub gpio write sub gpiob config 2013 xdimax com rev 2 17 37 SUB 20 SUB 20 API sub gpiob read sub gpiob write 3 7 1 sub gpio config Synopsis Int sub gpio config sub handle hndl int set int get int mask Configure GPIO state direction as input or output Parameters set Bits 0 31 of set parameter correspond to GPIOO GPIO31 configuration bits If GPIOn configuration bit is 1 then GPIOn direction is output otherwise it is input get Pointer to store current GPIO configuration read from SUB 20 mask Bit in set parameter will take effect only if corresponding mask bit is 1 With mask 0 function will only read current GPIO configuration Return value On success function returns 0 Otherwise error code Example gpio0 6 input gpio7 output rc sub_gpio_config hndl 0x00000080 config 0x000000FF read gpio configuration rc sub_gpio_config hndl 0 sconfig 0 See also Error Codes 3 7 2 sub gpio read Synopsis int sub_gpio_read sub_handle hndl int get Read GPIO input status Function reads logic value 1 high 0 low directly from GPIO pin Parameters get Pointer to store received GPIO input status Bits 0 31 of get correspond to GPIOO GPIO31 input statuses Return value On success function returns 0 Otherwise error code See also
52. x_sz bytes transmitted and either rx_sz bytes received or one of the timeouts occurs see sub rs timing For 9bit transfer data in tx_buf and rx_buf has following format byte 0 byte 1 byten byten 1 bit 8 LSB bits7 0 bit 8 LSB Even bytes 0 2 4 contain 8 th bit in LSB Odd bytes 1 3 5 contain bits 7 0 Data is shifted out beginning from bit O see RS232 RS485 Frame format Parameters tx_sz and rx_sz should correspond to total number of bytes in tx_buf and rx_buf Return value On success function returns non negative value that denotes number of received bytes It can be less then rx_sz if timeout occurs Otherwise 1 will be returned and sub_errno will contain error code Example Set timing sub_rs_timing hndl RS_RX_AFTER_TX 0 1000000 200000 Transmit 3 bytes and try to receive up to 5 bytes in 1s with 200ms byte to byte timeout A 2013 xdimax com rev 2 17 51 SUB 20 SUB 20 API sub_rs_xfer hndl at r 3 rx_buf 5 Compatibility FW version 9 bit transfer support 0 2 2 or grater 3 11 FIFO Streaming Slave Modes FIFO is used for implementation of streaming data transfer and slave modes functionality such as SPI slave I2C slave Below is simplified block diagram of the SUB 20 FIFO module IN Dual Buffer sub_fifo_read sub_fifo_config sub_fifo_status sub_fifo_write 3 11 1 FIFO Functions sub fifo config sub fifo read
Download Pdf Manuals
Related Search
Related Contents
USER MANUAL Husqvarna 123HD60, 123HD65 Trimmer User Manual Sony SRS-AX10 User's Manual Seguro de Saúde Copyright © All rights reserved.
Failed to retrieve file