View previous topic :: View next topic |
Author |
Message |
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Wed Jun 08, 2016 6:08 pm Post subject: Xmega256D3 and TWIE compilation error |
|
|
Hello!
I'm having a first go at using I2C to try to add a RTC to an existing system. There, i only have the port E I2C available and i configure as follows:
'==Initialize I2C for BQ32000 RTC
'==configure the scl and sda pins
Config Sda = PortE.1
Config Scl = PortE.0
'==Use channel #4
Const RTC = 4
Open "twie" For Binary as #RTC
Config TWI = 100000
I2Cinit #RTC
Dim TWI_START As Byte
And i get a compiler error 31: Error : 31 Line : 711 Invalid data type [[0011] 0[TWIE_CTRL]]
I've tried adding a DIM TWIE_CTRL as Byte, but that doesn't do the trick..
Strangely, if i change the 'Open' line to:
Open "twic" For Binary as #RTC
then compilation runs fine; but i'm sure that would not work. (I haven't set up the hardware at the moment, so i have not tried to run the code yet.)
Could someone spread some light here?
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Wed Jun 08, 2016 6:30 pm Post subject: |
|
|
...config TWIE = ....
Read help "config twi" for details |
|
Back to top |
|
|
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Fri Jun 10, 2016 10:57 am Post subject: Problem solved |
|
|
laborratte wrote: | ...config TWIE = ....
Read help "config twi" for details |
Hello Laborratte. Thanks very much for your suggestion.
I eventually found the problem to be more basic in that there are some omissions in the xm256D3def.dat file. TWIC is defined completely, but there is some stuff missing for TWIE. (An cryptic remark was in the datasheet errata that suggests the reference to TWIE had been missing in earlier revisions of the documentation.)
Missing in 'xm256D3def.dat' is the definition of the addresses and the definition of the interrupt names. I took these from the xm128A1def.dat file and added them to xm256D3def.dat.
So i added:
;***************************************************************************
;** TWIE - Two-Wire Interface E
;***************************************************************************
TWIE_CTRL = 1184 ; TWI Common Control Register
TWIE_MASTER_CTRLA = 1185 ; Control Register A
TWIE_MASTER_CTRLB = 1186 ; Control Register B
TWIE_MASTER_CTRLC = 1187 ; Control Register C
TWIE_MASTER_STATUS = 1188 ; Status Register
TWIE_MASTER_BAUD = 1189 ; Baud Rate Control Register
TWIE_MASTER_ADDR = 1190 ; Address Register
TWIE_MASTER_DATA = 1191 ; Data Register
TWIE_SLAVE_CTRLA = 1192 ; Control Register A
TWIE_SLAVE_CTRLB = 1193 ; Control Register B
TWIE_SLAVE_STATUS = 1194 ; Status Register
TWIE_SLAVE_ADDR = 1195 ; Address Register
TWIE_SLAVE_DATA = 1196 ; Data Register
and
INTname45=TWIE_SLAVE,$005A,#TWIE_SLAVE_CTRLA.6,
INTname46=TWIE_MASTER,$005C,#TWIE_MASTER_CTRLA.6,
(These were listed as 'reserved' before..)
Now my code compiles fine! (I have tested for proper working yet!)
Thanks again and best wishes,
poesboes |
|
Back to top |
|
|
holli
Joined: 29 Jul 2010 Posts: 28
|
Posted: Tue Jun 14, 2016 8:25 pm Post subject: |
|
|
Unfortunately in all early XM...D3 chips TWIE was not available at all, see the datasheet Errata section. That's why it's not in the .dat files yet. Only the latest revision of the chips should have a proper working TWIE. If the register "Mcu_revid" of the chip reads a value lower than 8 there is no working TWIE. |
|
Back to top |
|
|
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Tue Jun 14, 2016 10:08 pm Post subject: Mmm.. yes.. |
|
|
holli wrote: | Unfortunately in all early XM...D3 chips TWIE was not available at all, see the datasheet Errata section. That's why it's not in the .dat files yet. Only the latest revision of the chips should have a proper working TWIE. If the register "Mcu_revid" of the chip reads a value lower than 8 there is no working TWIE. |
Thanks Holli. I just discovered that mention of the need for having a > rev 7 processor in the help example. Mine identified as just a revision 4, so indeed i'm out of luck there..
I did a quick attempt at getting a software based solution going, but i still see no action on the ports at the moment. In the attempt i added I2C.LIB; not sure if that's possible in combination with the xmega.lib? I suppose they both define the same I2C commands?
Or... ow, wait, i'll have to revert to the original definition file for the processor. Maybe it's now automatically assuming it's hardware ready. I'll try that first thing tomorrow.
Thanks again Holli. |
|
Back to top |
|
|
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Thu Jun 16, 2016 5:49 pm Post subject: Working on TWIC |
|
|
With a little tinkering i was able to move the BQ32000 I2C RTC to Port.C. And that's working beautifully; with hardware I2C!
The Texas Instruments BQ32000 is very nice to work with. It's largely compatible to the well-known DS1307, but runs of 3.0-3.6V. Furthermore it has a nice correction feature so one can adjust timekeeping from -63 .. +126ppm. It basically skips or adds counts once-in-a-while. It also has a 1Hz or 512Hz output. The 1Hz is affected by the timekeeping adjustment, so it's accurate and can be used well for generating interrupts. The 512Hz option is not adjusted. It can therefore be routed to a frequency counter to determine what the correction should be.
Also it can be backed by a primary- or rechargeable battery or a super capacitor. It has switching an charging circuitry on board.
It's only available as a SMD SOIC-8. (But SOICs are very easy to solder by hand..)
Only one tip: With the XMEGA, do indeed make sure to use 'I2Crepstart' where applicable.
Here's a little sample code. It reads the RTC to variables.
Code: | Read_RTC:
'Reads time and date from I2C and copy it to system RTC
I2cstart ' Generate start code
I2cwbyte RTCw ' send address
I2cwbyte 0 ' start address in BQ32000
I2crepstart ' Generate start code
I2cwbyte RTCr ' send address
I2crbyte tempb3 , Ack 'seconds
RTC_stop = tempb3 AND &B10000000 'Just D7
RTC_sec = tempb3 AND &B01111111
RTC_sec = Makedec(RTC_sec)
I2crbyte tempb3 , Ack ' minutes
RTC_osc_fail = tempb3 AND &B01111111 'Just D7
RTC_min = tempb3 and &B01111111
RTC_min = Makedec(RTC_min)
I2crbyte tempb3 , Ack ' Hours
RTC_Cent_EN = tempb3 AND &B10000000
RTC_Cent = tempb3 AND &B01000000
RTC_hour = tempb3 AND &B00111111
RTC_hour = Makedec(RTC_hour)
I2crbyte tempb3 , Ack ' Day of Week
RTC_Weekday = tempb3 AND &B00000111 'D7-D3 are and should always remain zero BCD convertion not needed; already binary
I2crbyte tempb3 , Ack ' Day of Month
RTC_day = tempb3 AND &B00111111 'D7-D6 reserved and should remain zero
RTC_day = Makedec(RTC_day)
I2crbyte tempb3 , Ack ' Month of Year
RTC_month = tempb3 AND &B00011111 'D7-D5 reserved and should remain zero
RTC_month = Makedec(RTC_month)
I2crbyte tempb3 , Ack ' Year
RTC_year = Makedec(tempb3)
I2crbyte RTC_CAL_CFG1 , NACK 'Subsequent reading of trickle charge registers is skipped. CAL_CFG1 sets 1Hz/512Hz output and ppm correction
I2cstop
return
|
|
|
Back to top |
|
|
|