Home

I2C Interface for QL-Emulators part 5

image

Contents

1. 280 1000 DEFine PROCedure I2C init 1010 CLS 1020 raml 174 ramis AE REMark PCF8570 address all address links open ie all address pins high A0 high 1030 ram2 172 ram2S AC REMark PCF8570 a A0 low 1040 ram3 170 ram3 AA REMark PCF8570 a A0 high 1050 ram4 168 ram4 A8 REMark PCF8570 a A0 low 1060 ram5 166 ram5S A6 REMark PCF8570 a AO high 1070 ram6 164 ram6 A4 REMark PCF8570 a A0 low 1080 ram7 162 ram7 A2 REMark PCF8570 a A0 high 1090 ram8 162 ram8S A0 REMark PCF8570 a closed ie all address pins low 1100 parallelAl 126 parallelAiSs 7E REMa address links open ie all address pins h 1110 parallelA2 124 parallelA2S 7C REMa A2 high Al high A0Q low 1120 parallelA3 122 parallelA3 7A REMa A2 high Al low AO high 1130 parallelA4 120 parallelA4 78 REMa A2 high Al low A0O low 1140 parallelA5 118 parallelA5 76 REMa Al high AO high 1150 parallelA6 116 parallelA5ss 7A REMa Al high A0O low 1160 parallelA7 114 parallelA6s 72 REMa Al low AO high 1170 parallelA8 112 parallelA7S 70 REMa address links closed ie all address pins 1180 parallell 78 paralleliS AE REMark open ie all address pins high 1190 parallel2 76 parallel2S 4C RE
2. ress ress ress ress A2 high Al 1 A2 high Al 1 low Low low Al high Al low Al low Al high Al high Al low ress links all ress ress ress low low low all all links A2 high A2 High A2 High A2 low A2 low A2 low all links l address links A2 high Al high low Ow Al high Al high Al low 1330 adda8 144 adda8 90 REMark PCF8591 address all address links closed ie all address pins low 1340 rtc 208 rteS DO REMark DS1307 real time clock one fixed address with this device 1350 digpot1 94 digpot1S 5E REMark DS1803 Digital Poteniometer all links open IE all address pins high 1360 digpot2 92 digpot2 5C REMark DS1803 Digital Poteniometer A2 high Al high A0Q low 1370 digpot3 90 digpot3 5A REMark DS1803 Digital Poteniometer A2 high Al low AO high 1380 digpot4 88 digpot4 58 REMark DS1803 Digital Poteniometer A2 high Al low A0O low 1390 digpot5 86 digpot5 56 REMark DS1803 Digital Poteniometer A2 low Al high AO high 1400 digpot6 84 digpot6 54 REMark DS1803 Digital Poteniometer A2 low Al high A0O low 1410 digpot7 82 digpot7 52 REMark DS1803 Digital Poteniometer A2 low Al low AO high 1420 digpot8 80 digpot8S 50 REMark DS1803 Digital Poteniometer all links closed ie all address pins low 14 30 DIM
3. TF Services I2C manual http www dilwyn me uk docs manuals index html Advanced I2C information but still worth a read to understand I2C protocols http www nxp com documents user_manual UM10204 pdf
4. tdata 7 1690 into not s 1700 USB to I2C converte PAUSE E ee return f second CR 1730 PRINT reset the flash PRINT 3 CHR opening Com port 200 REMark opening serial port PI LEDS flash du Note the S the USBtoI2C converter to finish Loring the USB to I2C i LT a Wat Sun BV products Y N is THEN PRINT Program Abborted STOP is resetting PAUSE 200 REMark Wait just making etc ser 440 DIM days 7 3 1450 RESTORE 1460 FOR a 1 TO 7 470 READ d 1480 daysS a d 1490 NEXT a 1500 DATA Mon Tue Wed Thu 1510 END DEFine I2C_init l 5206 1530 DEFine PROCedure I2C Start 1540 REMark Utilities for expl 1550 REMark 1560 REMark Start up 1570 REMark 1580 REMark Determine Com Port Number 1590 CLS PRINT 1600 sererror 0 1610 INPUT Is USB to I2C connected 1620 IF i n 1630 PRINT Please wait USBtoI2C for power up reset of sure the converter is ready 1640 INPUT Enter com port number 1 3 1650 serS Ser amp ser 1660 PRINT Opening Com Port ser 1670 DoCom 1680 PRINT Please wait ensuring USB to I2C converter ready afte m sends USB ring this proce to I2C converter ss If vou do 1 then 3 the convert REMark Car converter fi ent required on 1710 print replv print replv PRINI after sendi
5. 060 data 6070 device d non print repl 6080 6090 6100 6110 6120 6130 PAUSE 5 NEXT a END DEFine ledcount DEFine PROCedure input test REMark REPeat input loop PRINT ines non p used as an input a t replv REMa buffer is clea EX parallelA1 rin red hexadd H 3 s parallelA1s ff p CHRS 13 REMark n re set high rk Stops printing the USB to I2C reply A1 ff p CHRS 13 REMark s start p end of message to USB to I2C reply REMark Stops printing the USB to I2C reply also ensure serial buffer is cleared s parallelA1S 00 p CHRS 13 reply REMark Stops printing the USB to I2C reply also PRINT 3 s parallelA1S amp hhexS amp p CHRS 13 non print _reply REMark Stops printing the USB to I2C reply also d to nsur also hexadd hexaddril parallelins HEXS adds to the device REPeat input 1 PRINT 3 s pa oop rall S 59 0 PRINT Y extract_read_data AT FOR a 1 TO 200 N ax KEYROW 1 IF ax amp amp 64 THEN EXIT END REPeat input END DEFine input CJ XT a input loop _ loop test the HEX device address ins g 1 p CHRS 13 REMark reads input for reading Data return from selected Now if you run this program you should get a result like this this is the return from my test card which has all the
6. 2350 2360 2370 2380 2390 2400 2410 2420 2430 2440 2450 2460 2470 2480 2490 2500 NEXT count arrayt 10 I12CDev arrayt 10 arrayt 1 FOR count arrayt TO 10 I2CDevices count NEXT count END DEFine decode I2C device DEFine PROCedure display I2C devices found PRINT PRINT Addresses PRINT Hex Binary Decimal Type of device FOR count 1 TO 10 HexDec 0 I2CDevS 12CDevices count HexDec HEX I2CDevS HexBinS BINS HexDec 8 IF count gt 1 AND count lt 9 THEN PRINT count amp I2CDev SHexBinS HexDec we 2510 1 HexDec We 2520 2530 2540 2550 2560 2570 2580 2590 2600 2610 2620 2630 2640 2650 2660 2670 2680 2690 2700 2710 2720 2730 2740 2750 2760 2770 3000 3010 3020 3030 3040 3050 3060 3070 3080 IF count gt 10 THEN PRINT count amp I2CDevS amp amp amp HexBinS amp IF I2CDev IF I2CDevs IF I2CDev s PRINT No Device Found IF I2CDev 1 PRINT PRINT PRINT PRINT PRINT PRINT DS1803 Digital Potentiometer PCF8574A Parallel I O PCF8591 A D amp D A PCF8570 256 Byte RAM DS1307 RTC Real Time Clock IF I2CDev IF I2CDev IF I2CDev NEXT count END DEFine display I2C devices found ee o A ee ee a 1 I Hew ee BA A ta A A D 7 Fine PROCedure DoCom EN ERRor IF ERR_NI sererror 1 PRINT Erro
7. I2C Interface for QL Emulators Part 5 In this part I will deal with some updates and share my experience of using the BV4221 V2 I will start with the BV4221 V2 from ByVac BV4221 V1 BV4221 V2 The originally version of the BV4221 was a PCB with the following dimensions 32mm x 25mm The version 2 PCB is 45mm x 40mm Version 2 PCB also has screw fixing holes as well The other major feature differences between the two version is shown below e SPI interface added e I2C address finder added e Master clock rate selectable e Inspector mode operates at 100k e SV or 3V3 logic switchable e Two on board voltage regulators This does offer some interesting opportunities One of which I have included in my new routines that is the I2C address finder By using this it is possible to check which I2C devices are connected to the converter The return from the converter when the x command is used are the address es of all I2C devices connected From the address range it is possible to determine what types of device are connected This done from the first digit in the address hex code as follows Address in hex Device Ax PCF8574 Parallel port 4x MCP23017 Parallel port More on this device later Sx DS1803 Potentiometer Tx PCF8574A Parallel port Ox PCF8591 AD DA converter Ax PCF8570 RAM DO DS1307 RTC Real Time Clock Note the DS1307 has only one address unlike the remaining devices wh
8. Mark Al high A0O low 1200 parallel3 74 parallel3S 4Aa REMark Al low AO high 1210 parallel4 72 parallel4 48 REMark Al low A0O low 1220 parallel5 70 parallel5S Ags REMark Al high AO high 1230 parallel6 68 parallel6S 44 REMark Al high A0O low 1240 parallel7 66 parallel7 42 REMark Al low AO high 1250 parallel8 64 parallel8S A0 REMark closed ie all address pins low 1260 addal 158 addalS 9E REMark PCF8591 open ie all address pins high 1270 adda2 156 adda2S 9C REMark PCF8591 A0 low 1280 adda3 154 adda3S 9A REMark PCF8591 A0O high 1290 adda4 152 adda4 98 REMark PCF8591 A0 low 1300 adda5 150 adda5 96 REMark PCF8591 A0 high 1310 adda6 148 adda6S 94 REMark PCF8591 A0 low 1320 adda7 146 adda7 92 REMark PCF8591 dd dd dd dd dd dd dd 5 k gh k K F m k low add add add add add add add ress ress ress ress ress ress ress PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 PCF8574 A2 high A2 high A2 high A2 ow A2 low A2 low all add A add A add A add A add A add A add A add A add address address address address address address address address ress al ress ress ress ress A2 ress A2 ress a2 ress
9. REMark PRINT USBtoI2C Converter now in Decimal mode 1880 REMark PRINT 3 CHRS 13 1890 REMark print replv rem displays current address in decimal form 1900 PRINT 1910 END DEFine I2C Start 1920 1930 DEFine PROCedure print_reply 1940 cS 1950 REPeat loop 1960 aS INKEYS 3 1970 IF a THEN GO TO 1960 1980 IF aS CHRS 13 THEN EXIT loop 1990 cS c amp a 2000 PRINT aS 2010 IF aS gt THEN EXIT loop 2020 END REPeat loop 2030 END DEFine print_reply 2040 2050 DEFine PROCedure non print reply 2060 cS 2070 REPeat loop 2080 aS INKEYS 3 2090 IF aS THEN GO TO 2080 2100 bS a 2110 c c amp b 2120 IF aS gt THEN EXIT loop 2130 END REPeat loop 2140 END DEFine non print replv 21505 2160 DEFine PROCedur xtract read data 2170 ds 2180 REPeat data loop 2190 aS INKEYS 3 2200 IF aS THEN GO TO 2190 2210 IF aS CHR 13 THEN EXIT data loop 2215 IF a gt THEN EXIT data loop 2220 bS a 2230 dS d amp b 2240 END REPeat data loop 2250 END DEFine extract read data 2260 2270 DEFine PROCedure decode I2C device I2CDS 2280 I2CDev 1 DIM I2CDevices 10 2 HexC 1 12CTempS 2290 2300 2310 2320 2330 dlen LEN I2CD FOR count 1 TO dlen IF I2CDS count THEN I2CDev I2CDev t1 NEXT count I2CTemp 12CTemp amp 1I2CDS count HexC HexCt1 IF HexC 3 THEN HexC 1 I2CDevices I2CDev I2CDevices I2CDev amp I12CTemp I12CTemp 2340
10. devices with the exception of the MCP23017 which we will come to next gt opening Com The print_r erter which nt not an I2C command Reply from second CR sent t ignore this verter U m Number s inected to the IZC bus A RT teal Time Clo Found Found Found Found Found 5 7 x 8 1 he hek mi hm hl hub hek jfa That is all for this time Next time I will look at a cheaper alternative the PCF8574 A parallel device References Please note I used the original VI of the BV4221 BvVac now supplv V2 which also has a SPI interface The commands are the same so the programs listed in the article should still work http www byvac com bv3 index php route product category amp path 44 PCF8570 Ram Data Sheet http www nxp com documents data_sheet PCF8570 pdf PCF8574 A Data Sheet http www nxp com documents data_sheet PCF8574 pdf http focus ti com lit ds symlink pcf8574 pdf PCF8591 Data Sheet http www nxp com documents data_sheet PCF8591 pdf DS1307 RTC Real Time Clock http datasheets maxim ic com en ds DS 1307 pdf DS1803 Digital Potentiometer Data Sheet http datasheets maxim ic com en ds DS 1803 pdf MCP23017 Data Sheet http www microchip com wwwproducts Devices aspx dDocName en023499 I2C Tutorials http www robot electronics co uk acatalog I2C_Tutorial html http www i2c byvac com ar_foundation php http doc byvac com index php5 title I2C_Foundation SPI
11. ent as is from the SMSQ commands such as HEX which returns the letters in upper case this can cause problems For example if you send the line s AO p what happens is you end up changing the device address to 00 Since upper case A is the change address command for the converter However if you send s a0 p then everything is OK But note the converter returns these hex letter digits in upper case confusing So you will find in my revised program below a routine to convert upper case hex letters to lower case to be sent to the converter I also took the opportunity to improve the user experience and error trapping as well as running the BV4221 V2 in hex mode only so as to keep away from the bugs outlined above Also I added some features which the version 2 converter has which the version 1 does not As always my programs are just there to show what can be done they are not fully developed just to get you going for guidance and examples of how to use the I2C bus with this converter So you will find the new common routines and start up routine below As always I have commented them so you can see what is going on 10 REMark I2C test routines 20 I2C init 30 I2C Start 50 PRINT 60 PRINT LED Flash 70 ledflash 80 PRINT 90 PRINT LED Binary Count ledcount PRINT PRINT PRINT Input Test Press Space bar to exit test input test PRINT fay Ww ODO OOOO PRINT End CLOSE 3 STOP
12. his series I did say and I quote Please note I used the original V1 of the BV4221 ByVac now supply V2 which also has a SPI interface The commands are the same so the programs listed in the article should still work Well this remark was made on the basis of the manual for the BV4221 V2 which I had read just to make sure there was nothing that would stop things working However when it come to trying things practically it turned out not to be the case The protocols are nearly the same but the BV4221 V2 responses are slightly different There are subtle differences between the original BV4221 and the version 2 Which is stated in the BV4221 V2 user manual But the manual is not that clear on what these differences are This has meant I have had to rewrite the start up routines to reflect these differences The first difference is the time it takes for the BV4221 V2 to initialise this is around 4 seconds The original converter was virtually instant or certainly less than 1 second Or put another way I never caught myself out with the original converter not being ready to go when I started things up So you will now see that I have put in a couple of PAUSE statements to slow things down during to first start up stages The second difference is that on V1 the end of the received strings was character 32 which is the Space character Which affected my original extract_read_data routine The third thing I found was the returns to command
13. ich use the second digit x to select multiple devices on the I2C bus up to 8 devices with the devices we having been using in this series It is outside to scope of this series of articles but the BV4221 V2 does have other bus system which can be used with the I2C bus system this is called SPI Serial Peripheral Interface bus By the way if you wondering what the I2C I squared Cee means it is Inter Integrated Circuit bus I will not be going in the SPI now but may revisit it in a later article However the two interfaces are not a million miles apart in that they are both serial interfaces the I2C uses two wires where the SPI bus uses four Having said that the protocols used are very similar Typical SPI devices are the same as I2C devices but SPI being much faster is also used on memory devices and displays The MMC standard SD Cards for example have an SPI interface Could be an interesting project But after the problems Adrian Ives had with his SD Card products not one I will try So if you understand the workings of one bus system it is not a big step to the other Please see the references below for further information The ByVac I2C Foundation pages are a very good place to start In my original articles on using the USB to I2C converter I was using version 1 of the BV4221 Which is now no longer available Recently I have purchased some BV4221 V2 s so could test all my programs using this version Now in part one of t
14. ng CR The print replv is call r mav not be fullv reset riage Return to set the baud in the first pass to inialise USB to I2C H From USB to I2C converter to handle the first Reply ed twice rom the USB to I2C converter which is ane 1720 PRINT 3 CHRS 1 s cho of the CR sent L3 print_reply print_reply PRINT Reply from just ignore this 1740 PRINT 3 V CHRS 13 REMark Command to USB to I2C converter for converter firmware version 1750 PRINT Return USB Converter Version Number 1760 non_print_reply extract_read_data 12CVer d PRINT I2CVer non_print_reply 1770 PRINT 1780 REMark print replv rem returns a device address in decimal 1790 PRINT 3 x CHRS 13 REMark This command finds I2C device adresses on the I2C bus 1800 PRINT I2C devices connected to the I2C bus 1810 extract read data PRINT d I2CDevSs d non print replv REMark This should return all the device addresses that are on the I2C bus 1820 decode I2C device I2CDev 1830 display I2C devices found 1840 PRINT 1850 REMark PRINT 3 D CHRS 13 REMark send command to put USB to I2C Converter into decimal mode Not recommended with V2 converters 1860 REMark non print replv 1870
15. r opening com port ser PRINT No Port open ND IF ND WHEN EMark Set the size of the communications buffer to 16K mouff 8192 2 L El O AUD ser 115200 _ BUFF ser Combuff Combuff sererror 0 THEN PRINT Comport amp serS amp open DEFine DoCom p HHUWoQbobod U Z j D DEFine PROCedure hex case con uhex hexi uhex 1 hex2 uhex 2 uhil CODE hex1 IF hex1S gt A AND hex1S lt F THEN uhl uhl 32 uh2 CODE hex2 IF hex2S gt A AND hex2S lt F THEN uh2 uh2 32 lhexS CHR uh1 amp CHRS uh2 END DEFine hex case con PCF8574 or MCP23017 Parallel I o EN 3 serS ir REMark i ignore hardware handshake r raw data 3090 4000 4010 4020 4030 4040 4050 4060 4070 4080 4090 4100 5000 5010 5020 5030 5040 5050 5060 message to conve ensure se DEFine PROCedure l FOR a 1 TO 10 PRINT 3 s parallel USB to I2C converter dflash rter non p rint PAUSE 25 PRINT 3 non print rial buffer is cleared PAUSE 25 NEXT a END DEFine ledflash DEFin PROCedur FOR a 0 TO 255 hhex HEXS a 8 PRINT a hhexS hex case con hhex hhexS lhex ledcount ensure serial buffer is cleared 5070 5080 5090 5100 6000 6010 6020 any 1 6030 ensure serial 6040 hexadd 8 REMark from 6050 6
16. s such as V which asks for the version number of the converter was not as expected or the same at the version 1 converter Also the response to the first CR carriage return was also not the same at the original converter Now in my original programs I set the converter into decimal mode This is where things caused the biggest problems Since in Hex mode there was no difference between V1 and V2 In decimal mode on V2 the converter does not issue a CR after the version number I informed ByVac and they agree this is a bug and will be fixed in the next issue of firmware However I have no idea when or if this will happen So it is better to run the BV4221 in Hex mode I also found the same problem with the new commands on V2 such as x which returns the addresses if devices connected to the I2C bus Useful command this one as you will see from the updated program below So it is best to stay in hex mode Other than the start up times and issuing CR s there are no differences in using the commands between V1 and V2 One other bug I discovered and also reported to ByVac is that in decimal mode returns from the converter are getting truncated to two digits This causes problems in reading data from devices because any return greater than 99 is now incorrect So for example 255 get returned as 55 Because I wrote the original routines in decimal mode I was not aware the command strings are case sensitive So if the hex numbers are s

Download Pdf Manuals

image

Related Search

Related Contents

2 - Maxcess  Metra OESWC-LAN29H wire connector  HP10F型ベローズ式直動型減圧弁取扱説明書    Mobilis C2 Lady Mini  User Manual – CLUB DIRECTORY How to update key club details  Securing Designs Against Scan-Based Side  

Copyright © All rights reserved.
Failed to retrieve file