I'm confused with sbi cbi commands?

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

I'm trying to add some debug to my ASM and wanted to see it on a scope. So I simply used

 

sbi PORTB,2;//debug

and

cbi PORTB,2;//debug

 

But I only see one condition not both? I know my analyzer runs 4 times as fast as my device and my DDRB is set correctly. 

 

If I only run the set command I get [```````] condition is hi. if I run a clear command I get [_______] condition is clear. but when running a set and clear I see the last operation only. [_______]  where I'd suspect to see  [````_____] .

 

In my C code I can just set the PORTB receptively and I get exactly what I'd expect to see. Even if I set the condition in ASM and clear in C it works as expected. For some reason (unknown to me) I do not see the change when using the two asm commands only.

 

 

Here is an exmaple

	sbi PORTB,2;//debug
#if USB_CFG_IMPLEMENT_FN_WRITEOUT   /* if we have data for endpoint != 0, set usbCurrentTok to address */
    andi    x3, 0xf             ;[32]
    breq    storeTokenAndReturn ;[33]
    mov     token, x3           ;[34] indicate that this is endpoint x OUT
#endif
storeTokenAndReturn:
    sts     usbCurrentTok, token;[35]
doReturn:
cbi PORTB,2;//debug
    POP_STANDARD                ;[37] 12...16 cycles
    USB_LOAD_PENDING(YL)        ;[49]
    sbrc    YL, USB_INTR_PENDING_BIT;[50] check whether data is already arriving
    rjmp    waitForJ            ;[51] save the pops and pushes -- a new interrupt is already pending
sofError:
    POP_RETI                    ;macro call
	RETI
	

 

but honestly my analyzer should have no issues picking up a

    cbi PORTB,2;//debug    
    sbi PORTB,2;//debug    
 

and does so in c with

 PORTB |= 0x04

 PORTB &= ~0x04

 

 

This topic has a solution.
Last Edited: Sun. Jul 29, 2018 - 08:10 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

first it should work

just make a simple forever loop (and nothing else).

 

2.

 PORTB |= 0x04

 PORTB &= ~0x04

I would expect that the compiler use SBI and CBI for those lines of code. (and not a read modify write).  

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

sparrow2 wrote:

first it should work

just make a simple forever loop (and nothing else).

Yes, OP is perhaps assuming too much about the behavior of his code.  He should write this simple loop and confirm that he can detect it.

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

I know my analyzer runs 4 times as fast as my device

That's meaningless garble.

 

What is the minimum pulse width you can capture & display?  Is glitch removal turned on?  If so, turn it off.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

For a "Are you even alive?!?!?!" type check, I tend to toggle a pin instead of pulsing it. Easier to spot on a scope or analyzer.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead.