From: Jan K. <kro...@ho...> - 2012-06-01 18:58:32
|
Hello, I have translate a I2C program thats working on the arduino. It is the 7segment display from Gravitech.us ===== ARDUINO ============================= #include <Wire.h> #define _7SEG (0x38) /* I2C address for 7-Segment */ const byte NumberLookup[16] = {0x3F,0x06,0x5B,0x4F,0x66, 0x6D,0x7D,0x07,0x7F,0x6F, 0x77,0x7C,0x39,0x5E,0x79,0x71}; void setup() { Wire.begin(); /* Join I2C bus */ delay(500); /* Allow system to stabilize */ } void loop() { /* Configure 7-Segment to 12mA segment output current, Dynamic mode, and Digits 1, 2, 3 AND 4 are NOT blanked */ Wire.beginTransmission(_7SEG); Wire.send(0); Wire.send(B01000111); Wire.endTransmission(); Send7SEG (1,NumberLookup[random(0, 9) ]); Send7SEG (2,NumberLookup[random(0, 9) ]); Send7SEG (3,NumberLookup[random(0, 9) ]); Send7SEG (4,NumberLookup[random(0, 9) ]); delay(500); } /*************************************************************************** Function Name: Send7SEG Purpose: Send I2C commands to drive 7-segment display. ****************************************************************************/ void Send7SEG (byte Digit, byte Number) { Wire.beginTransmission(_7SEG); Wire.send(Digit); Wire.send(Number); Wire.endTransmission(); } ======= and this is my amForth program ==================== marker -7seg- $38 value twi.7seg \ 7segment adress : init-7seg twi.7seg twi.start \ begin transmission $00 twi.tx $47 twi.tx twi.stop ; : send-7seg ( digit byte ) swap twi.7seg twi.start \ begin transmission twi.tx \ send digit, is position twi.tx \ send byte twi.stop ; : test-7seg init-7seg \ init the i2c connection $01 $3f send-7seg \ digit-1 => 0 $02 $06 send-7seg \ digit-2 => 1 $03 $5b send-7seg \ digit-3 => 2 $04 $4f send-7seg \ digit-4 => 3 twi.stop ; It is not working. It seems to hang. Can continue with a hard reset! Could I get some help to solve this? Thanks in advance. Cheers, Jan Kromhout Hellevoetsluis-NL |
From: Erich W. <ew....@na...> - 2012-06-01 19:36:52
|
Hi Jan, On 06/01/2012 08:58 PM, Jan Kromhout wrote: > It is not working. Where exactly is "it"? Can you talk to the twi device? Did you try twi.scan? It should report every device on the twi bus. Did you enable the twi subsystem? \ enable twi \ TWBR = $03, TWPS[10] = $03 ==> 28 kHz (f_cpu: 11059200) : +twi ( -- ) $00 TWCR c! $03 TWBR c! $03 TWSR c! ; This code snippet works on atmega32. Check the datasheet whether it is the same for your controller. > It seems to hang. Can continue with a hard reset! Cheers, Erich |
From: Jan K. <kro...@ho...> - 2012-06-01 20:52:04
|
Dear Erich What should I give in at f-cpu=16000000 Try twi.scan? But no result. Thanks for any help! Cheers Jan Jan kromhout Sacharovlaan 3 3223HM Hellevoetsluis-NL Op 1 jun. 2012 om 21:36 heeft Erich Waelde <ew....@na...> het volgende geschreven: > Hi Jan, > > > On 06/01/2012 08:58 PM, Jan Kromhout wrote: >> It is not working. > > Where exactly is "it"? > > Can you talk to the twi device? Did you try twi.scan? It should > report every device on the twi bus. > > Did you enable the twi subsystem? > > \ enable twi > \ TWBR = $03, TWPS[10] = $03 ==> 28 kHz (f_cpu: 11059200) > : +twi ( -- ) > $00 TWCR c! > $03 TWBR c! > $03 TWSR c! > ; > This code snippet works on atmega32. Check the datasheet whether > it is the same for your controller. > >> It seems to hang. Can continue with a hard reset! > > > Cheers, > Erich > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Amforth-devel mailing list for http://amforth.sf.net/ > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |
From: Jan K. <kro...@ho...> - 2012-06-02 17:34:00
|
Dear Erich, I have done what you wrote, seems to work.But when I look to te code of twi.frt I see some strange thing, or missing sommething. When I look into the code never is sending the address in twi.start \ send start condition : twi.start ( -- ) [ 1 7 lshift 1 5 lshift or 1 2 lshift or ] literal TWCR c! twi.wait ; Where should I put the address? Thanks for any help.Cheers, Jan > Date: Fri, 1 Jun 2012 21:36:24 +0200 > From: ew....@na... > To: amf...@li... > Subject: Re: [Amforth] TWI - 7segment display Gravitech.us > > Hi Jan, > > > On 06/01/2012 08:58 PM, Jan Kromhout wrote: > > It is not working. > > Where exactly is "it"? > > Can you talk to the twi device? Did you try twi.scan? It should > report every device on the twi bus. > > Did you enable the twi subsystem? > > \ enable twi > \ TWBR = $03, TWPS[10] = $03 ==> 28 kHz (f_cpu: 11059200) > : +twi ( -- ) > $00 TWCR c! > $03 TWBR c! > $03 TWSR c! > ; > This code snippet works on atmega32. Check the datasheet whether > it is the same for your controller. > > > It seems to hang. Can continue with a hard reset! > > > Cheers, > Erich > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Amforth-devel mailing list for http://amforth.sf.net/ > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel |
From: Erich W. <ew....@na...> - 2012-06-03 08:39:55
|
Hi Jan, On 06/02/2012 07:33 PM, Jan Kromhout wrote: > Dear Erich, > I have done what you wrote, seems to work. Very good! > But when I look to te code of twi.frt I see > some strange thing, or missing sommething. > When I look into the code never is sending > the address in twi.start \ send start condition > : twi.start ( -- ) > [ 1 7 lshift > 1 5 lshift or > 1 2 lshift or ] literal > TWCR c! > twi.wait > ; > > Where should I put the address? The address is just the first byte to be transfered. I use the following functions to send/receive n Byte to/from some address. Feel free to recycle them: \ send n bytes to addr : >i2c ( x1 .. xN.msB N addr -- ) twi.start twi.tx \ uses addr 0 do \ uses N twi.tx \ uses xN .. x1 loop twi.stop ; : <i2c ( N addr -- xN.msB .. x1 ) twi.start 1+ twi.tx \ uses addr 1- dup 0 > if 0 do twi.rx loop else drop then twi.rxn twi.stop ; As you can see, the first call to twi.tx sends the addr. If you have not downloaded the datasheet of your controller from atmel.com, please do so. I know, these datasheets are rather intimidating at first, however, they do include a lot of information, e.g. how to set the bits in TWCR and their meaning. I strongly suggest to consult the datasheet often. You will learn to read it. And amforth will let you access the registers and bits easily. Cheers, Erich |
From: Matthias T. <mt...@we...> - 2012-06-03 17:39:57
|
Hi Jan, I'm not an expert for TWI, some I've spend some time with EEPROM modules (dont use the code in the lib directory, its broken). > Dear Erich, I have done what you wrote, seems to work.But when I look > to te code of twi.frt I see some strange thing, or missing > sommething. When I look into the code never is sending the address in > twi.start That is absolutly ok. The TWI/I2C bus has some unique characteristics, one is that it can be considered stateful. The master has to send a start condition (some special combinations of voltages of the affected lines) and only after successfully aquiring the bus the master can continue. When the master has finished its job, it has to send a stop condition (some special voltage combination again) to release the bus for others (I2C is multi-master capable). Usually the first thing a master has to do after getting the bus is to select a device to communicate with by sending one byte (In your case the 0x38). If the devices answers with an ACK (see TWI status), everything works fine and the next bytes may be transmitted. Things can get more complicated if the device has to send data back to the master (EEPROMs)... Thus I suspect the arduino code sequence (I do not know the arduino language) Wire.beginTransaction(_7SEG) ... Wire.endTransaction(_7SEG) should be written as 0x38 constant _7SEG twi.start \ aquire bus _7SEG twi.tx \ select device .... twi.stop \ release bus, maybe reset the device state as well You may want to check the Atmel Appnote AVR315 for more information Its only 11 pages... HTH Matthias |
From: Jan K. <kro...@ho...> - 2012-06-03 20:48:12
|
Dear Matthias, Thanks for this. I have now a complete working I2C connection with my 7seg display and my arduino. Now I working on the tmp75 temperature controller (i2c) When this working I will publish the code for other newbies as I am! Thanks to all they helped me in the last time, this is a great forum!!! Cheers, Jan kromhout Sacharovlaan 3 3223HM Hellevoetsluis-NL Op 3 jun. 2012 om 19:39 heeft Matthias Trute <mt...@we...> het volgende geschreven: > Hi Jan, > > I'm not an expert for TWI, some I've spend some time with EEPROM > modules (dont use the code in the lib directory, its broken). > >> Dear Erich, I have done what you wrote, seems to work.But when I look >> to te code of twi.frt I see some strange thing, or missing >> sommething. When I look into the code never is sending the address in >> twi.start > > That is absolutly ok. The TWI/I2C bus has some unique characteristics, > one is that it can be considered stateful. The master has to send a > start condition (some special combinations of voltages of the affected > lines) and only after successfully aquiring the bus the master can continue. > > When the master has finished its job, it has to send a stop condition > (some special voltage combination again) to release the bus for others > (I2C is multi-master capable). > > Usually the first thing a master has to do after getting the bus is to > select a device to communicate with by sending one byte (In your > case the 0x38). If the devices answers with an ACK (see TWI status), > everything works fine and the next bytes may be transmitted. > Things can get more complicated if the device has to send > data back to the master (EEPROMs)... > > Thus I suspect the arduino code sequence (I do not know the > arduino language) > > Wire.beginTransaction(_7SEG) > ... > Wire.endTransaction(_7SEG) > > should be written as > > 0x38 constant _7SEG > twi.start \ aquire bus > _7SEG twi.tx \ select device > .... > twi.stop \ release bus, maybe reset the device state as well > > You may want to check the Atmel Appnote AVR315 for more information > Its only 11 pages... > > HTH > Matthias > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Amforth-devel mailing list for http://amforth.sf.net/ > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |