View previous topic :: View next topic |
Author |
Message |
oi18ct
Joined: 08 Mar 2022 Posts: 22 Location: North Branch, Minnesota
|
Posted: Tue Apr 19, 2022 2:53 pm Post subject: atmega4809 i2c execution |
|
|
Fairly new to bascom- and I am enjoying working with it!
I am testing various functions for a project, one of which is using i2c to pcf8574 expansion io and (eventually) pac1932 load monitor. Based on reading in help files, I would like to implement with hardware TWI instead of soft-i2c. So its working in software i2c currently with this configuration:
' cfg i2c master to pcf857x expansion io, all used as dq's
'$lib "i2c_twi.lbx"
'Config Scl = Porta.3
'Config Sda = Porta.2
Config Twi0 = 100000
i2cinit
const gpio01_readAddr = &H41 '65
const gpio01_writeAddr = &H40 '64
Dim si_dqCmd As Byte
Dim si_diVal As Byte
Dim Twi_start As Byte
under options --->compilier ---> i2c,spi,1wire the i2c clock is set to porta3 and data to porta2 to match the chips hardware twi pinout.
uncommenting '$lib "i2c_twi.lbx" is, I think, all that is necessary to enable hardware twi. uncommenting this line throws these errors:
Error : 222 Line : 2 Illegal character [expected (, got '' [_SDA]] , in File : C:\MCS\BASCAVR2085\LIB\I2C_TWI.LBX
Error : 1 Line : 2 Unknown statement [.EQU not found for:_SDADDR] , in File : C:\MCS\BASCAVR2085\LIB\I2C_TWI.LBX
Error : 387 Line : 2 IO address must be in range [0-31] [_SDADDR] , in File : C:\MCS\BASCAVR2085\LIB\I2C_TWI.LBX
while software i2c is working fine, I would like to deploy with hardware twi. Am I missing something in configuration?
(BASCOM-AVR version : 2.0.8.5 ) _________________ Lee |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 19, 2022 3:07 pm Post subject: |
|
|
you use the mega48xx. this means the i2c hardware is different. in short, soft i2c always works, the lib you included is intended for old AVR processors which have different I2C/TWI hardware.
you do not need to include a lib.
you need this :
Code: | Config Twi0 = 100000 'CONFIG TWI will ENABLE the TWI master interface
I2cinit 'this will manage pull up
'------------------------------------------------------------------
Dim Twi_start As Byte 'with UPDI you need this byte |
more about this you can read in the help in the xtiny, megaX topics. _________________ Mark |
|
Back to top |
|
|
oi18ct
Joined: 08 Mar 2022 Posts: 22 Location: North Branch, Minnesota
|
Posted: Tue Apr 19, 2022 3:28 pm Post subject: |
|
|
ok, thank you for the clarification that it is using the hardware twi without the library import as xtiny/mega480x. I was a bit confused by what I read. _________________ Lee |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 19, 2022 3:36 pm Post subject: |
|
|
yes i get that. it is confusing. especial when you start with a new processor. _________________ Mark |
|
Back to top |
|
|
oi18ct
Joined: 08 Mar 2022 Posts: 22 Location: North Branch, Minnesota
|
Posted: Tue Apr 19, 2022 9:29 pm Post subject: |
|
|
I can deal with occasional confusion (it happens more often than I like).
It's a fair trade for this software- I really like it. I spent the last 20+ years in motion controllers and IEC61131 PLC's. BASCOM is similar in structure to what I've gotten used to over the years. I can program C (sort of), but it's not fun. This is a nice alternative _________________ Lee |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Apr 20, 2022 8:41 am Post subject: |
|
|
yes it is a good alternative.
it is a platform that supports many AVR chips.
When you are a long time user it is not hard since all the subtle differences between AVR are small.
But when you start with a new processor as the mega4809, it can be hard because the help was written for the first AVR (25 years ago) and has been changed with additions for xmega and now xtiny/megax/avrx, and various options and configuration changes.
the help needs a rewrite, taking into account new users that start with new chips. _________________ Mark |
|
Back to top |
|
|
|