The reason for the problem is alluded to in the Atmel data sheet where they suggest that for some TWI modes the CPU clock speed must be at least 16x the TWI baud rate. This change will clear the problem.
#define HI2C_BAUD_RATE 62
I suggest you check if the 16x requirement is common in AVR processors and if so include a 16x test in hwi2c.h with an informative error message for unsuitable combinations.
regards TB
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The mega8 16x speed reference to slave mode is at the top of page 164 (Bit Rate Generator
Unit) but if the same formula is used in master mode then the limitation is relevant.
To use the 400khz TWI bus speed then the CPU must be faster than 6.4mhz
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using GCB Great Cow BASIC (0.98.01 2017-10-27) on Linux Mint 18.3
When attempting to compile programs with this configuration this unhelpful error is produced..
/opt/GCBASIC/include/lowlevel/hwi2c.h (508): Error: Cannot store -3 in the byte variable TWBR
The reason for the problem is alluded to in the Atmel data sheet where they suggest that for some TWI modes the CPU clock speed must be at least 16x the TWI baud rate. This change will clear the problem.
I suggest you check if the 16x requirement is common in AVR processors and if so include a 16x test in hwi2c.h with an informative error message for unsuitable combinations.
regards TB
Good spot. I was not of the 16x issue when I wrote the library a long time ago.
So, I understand. If the clock speed is as used at 1 then this mutliplier is an issue.
Can you point me to the bit in the datasheet? Should be resolvable.
The mega8 16x speed reference to slave mode is at the top of page 164 (Bit Rate Generator
Unit) but if the same formula is used in master mode then the limitation is relevant.
To use the 400khz TWI bus speed then the CPU must be faster than 6.4mhz
Cheers - you explaination is excellent.
Download and place in the lowlevel directory an updated library.
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/hwi2c.h
This library will issue a friendly warning and it will advise how to resolve the warning.
Cheers,
Evan
I have found an issue on test - the warning message was being issue when IC2 was not been being used. See https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/hwi2c.h for latest.