Greetings to all !!!
First post in this community, in which I have snooped for some time. I am developing a system with many buttons, LEDs, sensors and relays (model railroading), and I have decided to use the I2C bus.
I have programmed microcomputers and minicomputers in assembler since the time of the Zylog Z80 (remember?) and, after seeing what weighs a sketch of the Arduino IDE for turn on an LED when a button is pressed (both connected to a PCF8574), I have returned to the good old assembler.
So, please, don't tell me "why don't you program it in C". My work is programming in C++, PHP and others, and diversion (fun) comes from the Latin di-vertere (devote to something else).
Well, the problem I face now is that the AS7 simulator does not seem to correctly simulate the TWI device. The AS7 simulates an ATMega328P @16MHz, the TWBR value is 0x48 (for 100KHz at bus), and when I try to initialize TWI as master receiver at call twi_rx
testbuttons: ldi XL, LOW(twi_buff) ; Load buffer address into X ldi XH, HIGH(twi_buff) ldi rtmp, I2C_BTN_RD ; SLA+R (0x40) st X, rtmp ; address to buffer ldi rcnt, 2 ; R17 = buffer length (address + 1 byte read) call twi_rx ; Initialize TWI wait: lds rtmp, TWCR ; Wait for the reception to end andi rtmp, (1<<TWIE) ; this happens when TWIE is low brne wait . . [more stuff]
; Initialize TWI as Master receiver ; ; rtmp is R16 ; twi_rx: ldi rtmp, (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWSTA) sts TWCR, rtmp ; Set TWEN, TWIE, reset TWINT and init START condition ret
the code above produces this state in the simulator:
However, after 400 clock cycles, the TWINT flag has not been set, the TWI interrupt is not fired (yes, SEI has been executed previously) and the ISR for this device is not executed.
Perhaps, to completely simulate the operation of the device, I would need a Stimuli file, but shouldn't the setting of TWINT after TWSTA be immediate?
Thanks for your kind help and I wish you a happy New Year.
Laura.
EDIT: AV7 [7.0.1931] running on W7 Professional x64 SP1