Wrongly READ BITs from peripheral, error? Oshonsoft BASIC

ericgibbs

Joined Jan 29, 2010
14,698
hi,
All you have to tell me is which pin is connected as requested and show a 3 line clip from you program, covering the DRdy read.


Update:
I don't understand how the Compass readings you are posting are OK, with the exception of some values, [ which is the topic of this Thread, ie: errors in the 2s conversion] if the DRdy is not being used by the MCU and the logic analyser is showing no DRdy.???
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,802
hi,
All you have to tell me is which pin is connected as requested and show a 3 line clip from you program, covering the DRdy read.


Update:
I don't understand how the Compass readings you are posting are OK, with the exception of some values, [ which is the topic of this Thread, ie: errors in the 2s conversion] if the DRdy is not being used by the MCU and the logic analyser is showing no DRdy.???
Hi E,
Sometime in the past I got mixed up between [SSPBUF = rd_adr While Not SSPSTAT.BF] and [DRDY] and once I got it all to work and show Degrees, I forgot about it. I've only started looking a DRDY again after years.
C
 

Papabravo

Joined Feb 24, 2006
17,580
There is an object lesson here about comments being more than an after thought. Well constructed, meaningful comments are an invaluable aid not only to the original designer/coder but to any follow on attempt by others to understand and maintain the code. Think about writing the comments first and the code second; you may be glad you did someday.
 

ericgibbs

Joined Jan 29, 2010
14,698
hi C,
If you do not see the DRdy pin High, the Compass is not Ready.

If you never see the pin High, using the Logic Analyser after the Comp has been initialised , the Compass has not been initialised correctly or the DRdy pin is faulty in some way.

Use the Compass Self Test feature as a check.

E
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
2,802
There is an object lesson here about comments being more than an after thought. Well constructed, meaningful comments are an invaluable aid not only to the original designer/coder but to any follow on attempt by others to understand and maintain the code. Think about writing the comments first and the code second; you may be glad you did someday.
Hi P,
When I'm programming, I usually cut and past working sections in the best way I can, till something happens. Lately though I'm trying to be a bit more organised and structured, which is happening slowly.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
hi C,
If you do not see the DRdy pin High, the Compass is not Ready.

If you never see the pin High, using the Logic Analyser after the Comp has been initialised , the Compass has not been initialised correctly or the DRdy pin is faulty in some way.

Use the Compass Self Test feature as a check.

E
Hi E,
Ok.

I'm trying to figure out whay the DRDY PIN is not outputting. Something strange is wrong, as I can get READings and Degrees out, but as mentioned some BITs appear to be erronious.
I'll re-name the thread, as it is more about wrongly READ BITs than 2's compliment I think.
C
 

Papabravo

Joined Feb 24, 2006
17,580
Hi P,
When I'm programming, I usually cut and past working sections in the best way I can, till something happens. Lately though I'm trying to be a bit more organised and structured, which is happening slowly.
C.
You use what works for you until it doesn't.
We get too soon old, and too late smart
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
DRDY can also be read from status register, address 0x02, bit0
Hi J,
I wonder why the PIN isn't working? I can't check the actual chip PIN as the contact is under it.

Thanks for reminding me about the DRDY BIT, I'll give that a go. I suppose it's got to be READ in a small LOOP, until it switches, before moving forward.
C
 

ericgibbs

Joined Jan 29, 2010
14,698
I said LOOP, but I meant WEND/WHILE

hi,
Say that one of your peripherals failed to get a 'rdy' response to a WEND/WHILE, the program would wait forever.
There are Coding techniques that cover that eventuality, but it depends on how critical the failure is to the project.
Most times we just use a WEND/WHILE if it a non critical project.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
I said LOOP, but I meant WEND/WHILE

hi,
Say that one of your peripherals failed to get a 'rdy' response to a WEND/WHILE, the program would wait forever.
There are Coding techniques that cover that eventuality, but it depends on how critical the failure is to the project.
Most times we just use a WEND/WHILE if it a non critical project.

E
Hi E,
This is slightly beyond me at the moment, but if I try WEND/WHILE as a test, then change it later.

'J in T' wrote some clever stuff that guards aginst blocking, which is in the FUL program and will be added back as I proceed.

At the moment I have a test for DRDY BIT, which ON/OFF a LED, that appears to be flashing. (It's a bit fast, but further tests, should double check)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
hi,
How have you got these Bits Set.?
SSPSTAT.CKE = 1
SSPCON1.CKP = 0
E
Hi E,
Here:
C
Code:
Proc init_spi()
'4620
TRISC.3 = 0  'SCK to Slave
TRISC.4 = 1  'MISO
TRISC.5 = 0  'MOSI

'MODE 0,0
SSPSTAT.SMP = 0  'Input data sampled at middle of data output time
SSPSTAT.CKE = 0  '1 Output data changes on clock transition from idle to active
SSPSTAT.5 = 0  'I2C only
SSPSTAT.4 = 0  'I2C only
SSPSTAT.3 = 0  'I2C only
SSPSTAT.2 = 0  'I2C only
SSPSTAT.1 = 0  'I2C only
SSPSTAT.BF = 0  'If SSPBUF=1=Full

SSPCON1.WCOL = 0  'Collision detect
SSPCON1.SSPOV = 0  'Overflow
SSPCON1.SSPEN = 1  'Configure SCK,SD0,SDI,/SS
SSPCON1.CKP = 1  '[1]  'Clock Idle high, Active low [Clock Idle Low, Active High]
SSPCON1.SSPM3 = 0  '0010 = SPI Master mode, clock = FOSC/64
SSPCON1.SSPM2 = 0
SSPCON1.SSPM1 = 1
SSPCON1.SSPM0 = 0

End Proc
 

Attachments

jjw

Joined Dec 24, 2013
726
SSPSTAT.BF is read only, but does'nt matter unless it is trusted in the program to clear the BF bit.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
SSPSTAT.BF is read only, but does'nt matter unless it is trusted in the program to clear the BF bit.
Hi J,
SSPSTAT.BF is read only Understood.

but does'nt matter unless it is trusted in the program to clear the BF bit Not understood.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,802
Hi,
Not getting DRDY PIN to work, I tried a rough test to see if DRDY BIT would work.

I added a READ of the BIT before and after the CODE READs the Compass and here's the result.
C
 

Attachments

Top