TWI simulation in Atmel Studio 7 [7.0.1931]

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

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

This topic has a solution.
Last Edited: Fri. Dec 27, 2019 - 08:08 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I think you will find trying to get the simulator to do what you want with peripheral devices will take more time then working with actual h/w.

I used to write a lot of assembler, even did much of it by hand in the old days, but gave that up when I found a wonderful macro assembler named C.

You may want to get a copy of fluery's I2C functions and move on to working on the real issues in your project.

 

Happy New Year

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

657/5000

Thanks, Jim.

...when I found a wonderful macro assembler named C.

Well, I had already thought about this; after all, what I really want is to have fun with the model layout. I can always program in C / C ++ in AS7 and burn the program with avrdude and test the real thing.
I had already downloaded Fleury's library, but I was not convinced because it uses polling; however, when looking more closely, now it seems to me that TWI interrupt is not needed, since the MCU cannot make any decision until the status of 8 buttons is known.enlightenedAny change in buttons' state, however, is notified by /INT of PCF8574 feeding INT0.

Your comment has put me on a new path.

Thanks a lot,
Laura.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I reposted when I saw that my message did not appear.

Last Edited: Fri. Dec 27, 2019 - 08:15 PM