wend while DRDY_PIN or NOT DRDY_PIN

Thread Starter

camerart

Joined Feb 25, 2013
3,736
Hi,
I'm READing a compass module AK8963C with a PIC 18F46K20.

To READ the DATA, the DRDY_PIN has been tracked to a PIN on the PIC.

In the program I have:
---------------------------------------------------------
In the set-up is:
Symbol drdy_pin = RD.1
or
Symbol drdy_pin = PORTD.1
================
compss_cs = 0 'COMPASS ON

While not drdy_pin 'AK8963C DRDY PIN
Wend

rd_adr = 0x80 'READ 0x00 %10000000
WaitUs 1
SSPBUF = rd_adr
While Not SSPSTAT.BF
Wend
xhb_raw = SSPBUF
compss_cs = 1 'COMPASS OFF
--------------------------------------------------
No matter what I do, the program stops if I add 'NOT' but carries on if I leave 'NOT' out. Is this correct?

When a statement says e,g, WHILE PIN, does it mean while the PIN is HIGH or LOW, it isn't clear.
Cheers, Camerart.
 

djsfantasi

Joined Apr 11, 2010
9,186
WHILE PIN loops while the pin is HIGH

…or any non-zero value because non-zero values are always considered TRUE

I’m not familiar with the variant of Basic that you are using. Is NOT a reserved word meaning negation?

There are three possibilities here.
  1. NOT is not a reserved word and is being interpreted as a variable. Uninitialized explicitly, it’s being interpreted as having a value of TRUE.
  2. PIN has a non-zero value and the negation is bit-wise, resulting in another non-zero value, I.e. always TRUE. PIN would have to be exactly zero for this to work as you expect
  3. Syntactically when parsing this statement, your Basic is ignoring PIN
I would suggest placing parentheses around the logic equation, like this:
While (NOT PIN)​
And see if that improves the execution. By the way, this assumes NOT is the correct keyword for negation.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,736
WHILE PIN loops while the pin is HIGH

…or any non-zero value because non-zero values are always considered TRUE

I’m not familiar with the variant of Basic that you are using. Is NOT a reserved word meaning negation?

There are three possibilities here.
  1. NOT is not a reserved word and is being interpreted as a variable. Uninitialized explicitly, it’s being interpreted as having a value of TRUE.
  2. PIN has a non-zero value and the negation is bit-wise, resulting in another non-zero value, I.e. always TRUE. PIN would have to be exactly zero for this to work as you expect
  3. Syntactically when parsing this statement, your Basic is ignoring PIN
I would suggest placing parentheses around the logic equation, like this:
While (NOT PIN)​
And see if that improves the execution. By the way, this assumes NOT is the correct keyword for negation.
Hi D,
The only information I could find is:
--------------------------------------------------
WHILE A > 0
PORTB = A
A = A - 1
WAITMS 100
WEND
------------------------------------------
This tells WHILE what to do. The NOT also where there is nothing after the WHILE staement, had been added by other helpful people, who probably used what they know, in their own programming language.

I've tried various ideas, and will try yours as well.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,736
Do a very basic comparison without the NOT. Like:
While SSPSTAT.BF=1
or
While SSPSTAT.BF=0
Hi S,
As I can't visualise what a [ While SSPSTAT.BF=1 ] Test would look like, I tried:
Code:
compss_cs = 0  'COMPASS ON

While drdy_pin = 0  'AK8963C DRDY PIN
'rled = 1
Wend
rled = 1


    rd_adr = 0x80  'READ 0x00 %10000000
    WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    wia_raw = SSPBUF
   
'If drdy_pin = 1 Then rled = 1
'If drdy_pin = 0 Then rled = 0

    'rd_adr = 0x81  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    info_raw = SSPBUF
   
    'rd_adr = 0x82  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    st1_raw = SSPBUF
   
    'rd_adr = 0x83  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    xlb_raw = SSPBUF
   
    'rd_adr = 0x84  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    xhb_raw = SSPBUF
   
    'rd_adr = 0x85  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    ylb_raw = SSPBUF
   
    'rd_adr = 0x86  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    yhb_raw = SSPBUF
   
    'rd_adr = 0x87  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    zlb_raw = SSPBUF
   
    'rd_adr = 0x88  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    zhb_raw = SSPBUF
   
    'rd_adr = 0x89  'READ 0x00 %10000000
    'WaitUs 1
    SSPBUF = rd_adr
    While Not SSPSTAT.BF
    Wend
    st2_raw = SSPBUF
   

compss_cs = 1  'COMPASS OFF
The commented in LED comes on and stays on, and as you can see it does allow READing.

The string of 0x80s should increment, but that's a different thing.
NOTE: My incrementing tests are commented out.
NOTE: The LED doesn't flicker.
C
 

Attachments

jjw

Joined Dec 24, 2013
823
"While NOT drdy_pin" is correct and is the same as "While drdy_pin=0"

It may hang here because drdy_pin is 0, PORTD.1 is not an input or connection problem between Rdy and PORTD.1
You can test this by looking the Rdy pin.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,736
Hi D and S,
It works with
--------------------------------------
While drdy_pin = 0
Wend
-------------------------------------
See attached, The D/S says that the DRDY_PIN should be HIGH when DATA is in, and drop when the first READing is READ, which is now happening.
ThanksC.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,736
"While NOT drdy_pin" is correct and is the same as "While drdy_pin=0"

It may hang here because drdy_pin is 0, PORTD.1 is not an input or connection problem between Rdy and PORTD.1
You can test this by looking the Rdy pin.
Hi J,
Yes, I noticed that there is a
-----------------------------------------
While Not SSPSTAT.BF
Wend
----------------------------------------
which appears to be working, and this puzzled me.
NOTE: when these are typed in with small letters, the 'N' capitalises, which says to me, that this is recognised.
I've checked and checked the DRDY_PIN connections with a meter, logic probe and Oscilloscope, and it is connected the correct way around.

This has been a very precise procedure to get this to work so far, with many hours trying. The CS and READS, must be dead on, which seem to be ok today.

I'll investigate: NOT again, once I've proved what's working today, is robust.
Thanks,
P.S. I couldn't resist trying 'NOT' and it is no working :) No idea what the probem/s were before.
C.
 
Last edited:
Top