Why is this code in simulator not working

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

I have been learning how to program the Parallax SX28 chip and it seems after 2 weeks I have lost most of my skill at programming Atmel chips.

Anyway I am working on a design where I will use 6 tiny13's to collect data and send that data to the SX chip. The design will have all of the tiny13 PB0 tied together as well ast PB1 and PB2 ports, so 3 buss lines. All pins will be pulled up/input. The SX will pull down PB3 on each chip one at a time, when a chip gets a low signal on its PB3 it flips any or all of PB0,PB1,Pb2 to outputs to pull the SX lines low, the SX chip will read the 3 bits and release the PB3 line.

The code for the tiny13 output is below, it works on the chip but not in the simulator because pinb,3 is never set by the pullup.

Since no pin will be set HIGH and all three of the pins on any chip will only be output LOW I have another question. Should I use resistors or diodes on any of the pins connecting the SX chip?

; ========================= Initialize variables =======================

ldi data, 0b00000111
ldi zero,0x00

;========================== Set data direction bits ====================
ldi Temp,0b00000000       ;1=output 0 = input 
out DDRB,Temp
ldi temp, 0b00001000      ;1=pullup if input high if output
out portb, temp

; ========================= Setup interrupts ===========================

; ==========================  Main Program =============================

Mainloop:

sbis pinb,3     ;Skip Next line if port is still high
rjmp senddata   ;If Low send data
rjmp Mainloop   ;otherwise loop

senddata:
out DDRB,data   ;Put data on pins 2..0 (pulls other uc pins LOW if bit = 1)

sending:
sbis pinb,3     ;Skip next line if port is high
rjmp sending    ;If held low just wait

out DDRB, zero  ;Reset pins to input
rjmp mainloop   ;Go back to main loop
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
pinb,3 is never set by the pullup

I've also observed this behavior, also (perhaps by coincidence) using the ATtiny13 simulator.
At the time, I concluded (rationalized?) that while it might be a simulator bug it might be
a matter of definition: Since the simulated PINB can't be physically wired to anything, the
external signal can only be "driven" by the user, by twiddling the register. The user can
only choose 1 or 0, not "floating", so how does the simulator figure out when the pullup is
relevant and when it isn't? Maybe the people over in the Studio 4 Forum have a better answer.
Quote:
Should I use resistors or diodes on any of the pins connecting the SX chip?

I'm not a EE, but I know that this scheme is also used by I2C (TWI). I2C specifies pullups,
and TWI can sorta-kinda be managed using the internal pullups; however it becomes unreliable
with higher speeds and longer wires (higher capacitance?). My observation from a casual
survey of Forum posters is that TWI, and probably your scheme as well, will require external
pullups sooner or later.

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

The processors will all be on one board connected with traces so no long wires. Communication is a simple Hold one line low from the master, the slaves (tiny13's) respond with pulling the masters pins low for each bit on, I am not sure yet how long of wait time I will need because the SX has a prefetch que , as it pulls the comm line low it will have to wait some amount of time before reading the input pins, but my scope will tell the story when I get to that point.

I have looked at ADC chips to do this and it just comes out cheaper to use 6 processors.