Wrongly READ BITs from peripheral, error? Oshonsoft BASIC

ericgibbs

Joined Jan 29, 2010
15,349
hi C,
When you have finished the Saving routines, this is a conversion code to Signed Single demo.

The Code between these two
''--------------------------------------------------------------------------
is the actual Code.
E

Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''''Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

Define CLOCK_FREQUENCY = 8
AllDigital
TRISA = %00000001
TRISB = %00000000
TRISC = %00000001
PORTA = %00000001
PORTB = %00000000
PORTC = %00000000
PORTE = %00000000

PIR1 = 0
PIR2 = 0
PIE1 = 0
PIE2 = 0
IPR1 = 0
IPR2 = 0

ADCON0 = 0x03
ADCON1 = 0x0e
ADCON2 = %10100100
OSCCON = %01111010  'internal 8mhz

''--------------------------------------------------------------------------
Dim raw_x As Word
Dim Comp_x As Single

Disable High
Disable Low

Hseropen 9600

raw_x = 0x0002  'Test ONLY


main:
Hserout HexStr(raw_x), "   ",  ''' Test ONLY

'convert 2s to Single
If raw_x.15 = 1 Then
Comp_x = raw_x Nxor 0xffff
Else
Comp_x = raw_x
Endif


'' Test ONLY
Hserout "Compass x= ", #Comp_x, CrLf
raw_x = raw_x - 1

Goto main
'----------------------------------------------------------------------------------
End
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi C,
When you have finished the Saving routines, this is a conversion code to Signed Single demo.

The Code between these two
''--------------------------------------------------------------------------
is the actual Code.
E

Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40

''''Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

Define CLOCK_FREQUENCY = 8
AllDigital
TRISA = %00000001
TRISB = %00000000
TRISC = %00000001
PORTA = %00000001
PORTB = %00000000
PORTC = %00000000
PORTE = %00000000

PIR1 = 0
PIR2 = 0
PIE1 = 0
PIE2 = 0
IPR1 = 0
IPR2 = 0

ADCON0 = 0x03
ADCON1 = 0x0e
ADCON2 = %10100100
OSCCON = %01111010  'internal 8mhz

''--------------------------------------------------------------------------
Dim raw_x As Word
Dim Comp_x As Single

Disable High
Disable Low

Hseropen 9600

raw_x = 0x0002  'Test ONLY


main:
Hserout HexStr(raw_x), "   ",  ''' Test ONLY

'convert 2s to Single
If raw_x.15 = 1 Then
Comp_x = raw_x Nxor 0xffff
Else
Comp_x = raw_x
Endif


'' Test ONLY
Hserout "Compass x= ", #Comp_x, CrLf
raw_x = raw_x - 1

Goto main
'----------------------------------------------------------------------------------
End
Hi E,
That's handy, thanks.
I'm still juggling with DRDY_BIT and DRDY_PIN.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Hi,
Can someone clarify this please:

I understand that there are 2x sections, marked blue.

Am I correct that they can be READ in a LOOP or from start to end, depending on the CS?

There are 3x3 dots, marked red, can someone describe
1/ 111

2/ 111,

3/ 111
C
 

Attachments

ericgibbs

Joined Jan 29, 2010
15,349
hi,
When the Comp has been set up, all you need to Read are the Addresses outlined in RED.

Set CS Enable
So a Read would start at Addr =0x02H [ check status]

IF
Ready then set Addr =0x03H which is the X Low Byte Addr, by sending 8 Clock pulses.

Continue sending clock pulses, the next 8 clock pulses after the Addr clocks will Return the X Low Byte data, keeping sending clock pulse and get the X High Byte and so on until you have Read and Saved the Y Low,High...... Z Low High byte [ which is at 0x08H] then Stop the clock, disable the CS line.

E

Update:
Remember you are using the devices auto address increment option, [ which will start at the initial address you have written] by sending continuous clocks while keeping the CS enabled.
ESP_ 583 Jul. 12 10.54.png
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi,
When the Comp has been set up, all you need to Read are the Addresses outlined in RED.

Set CS Enable
So a Read would start at Addr =0x02H [ check status]

IF
Ready then set Addr =0x03H which is the X Low Byte Addr, by sending 8 Clock pulses.

Continue sending clock pulses, the next 8 clock pulses after the Addr clocks will Return the X Low Byte data, keeping sending clock pulse and get the X High Byte and so on until you have Read and Saved the Y Low,High...... Z Low High byte [ which is at 0x08H] then Stop the clock, disable the CS line.

E

Update:
Remember you are using the devices auto address increment option, [ which will start at the initial address you have written] by sending continuous clocks while keeping the CS enabled.
View attachment 243267
Hi E,
Yes, this is something I've done, but I also experiment, to find things out.

It may seem petty but do you have answers to my questions, as shown in #83 please, so that I can add coments to the D/S, please?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Using dots is a common method of showing a continuation of a sequence between two end limits.
ie: a ... z means a thru to z.
0x01 thru to 0x0B
0x01 .... 0x0B means 0x01 0x02 0x03...... 0x09 0x0A 0x0B
Hi E,
I think I've got it, am I correct that 2/ and 3/ are go on for ever, or until CS?

I saw ~ and ... to mean the same but they're slightly different.
Thanks, much clearer.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
As I haven't been able to get correct Compass READings so far, I am trying different settings.

In particular the MODE settings, SINGLE MEASUREMENT MODE.
I am able to set different MODEs, but not 'single measurement mode'
Here's the results:
Any ideas, please?
Update: I think maybe MODE0 should be set just before the READ section, but not sure?
C
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Hi,
As mentioned, I prefer DRDY_PIN to DRDY_BIT, so this is what I've been trying to get to work.

I've gone back to the compass setting up stage, bit by bit.

After changing a setting to 'single measurement READ' the program stalls just after it. I'm fairly sure it's not being READ correctly.

I'm not actually stuck, but going though trying to get the digital analyser to match #77. up to now, I've needed to add very short WAITs to get it to READ.

Here is a test analyser READing for interest: As can be seen the DRDY_PIN is now switching, so onward.
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Where in your Code are you setting CNTL1 register MODE[3:0] bits, single measurement.?

MODE[3:0]=“0001”
Hi E,
There is a section of CODE named:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'COMPASS INITIALISATION
'SETUP COMPASS
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
One of the sections look like this:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WaitMs 50
wr_adr = 0x0a 'CONFIG CNTL1 reg
wr_byte = 0x11 'WRITE CONFIG 16BIT, Single measurement mode
'wr_byte = 0x12 'WRITE CONFIG 16BIT, CONT MODE 1
'wr_byte = 0x16 'WRITE CONFIG 16BIT, CONT MODE 2
compss_cs = 0 'CHIP SELECT COMPASS ON
Call periph_wr(wr_adr, wr_byte)
compss_cs = 1 'CHIP SELECT COMPASS OFF
WaitMs 50
rd_adr = 0x8a '0
rd_Byte = 0 'Dummy BYTE
compss_cs = 0 'CHIP SELECT COMPASS ON
data = periph_rd(rd_adr)
compss_cs = 1 'CHIP SELECT COMPASS OFF
Hserout "READ 0x12 =18 ", #data, CrLf
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FUNCTIONS-------------------------------------------------
Function periph_wr(arg1 As Byte, arg2 As Byte) As Byte

WaitUs 1
SSPBUF = wr_adr
While Not SSPSTAT.BF 'If SSPSTAT.BF = 0 then WEND (Buffer flull BIT).
Wend
WaitUs 1
SSPBUF = wr_byte
While Not SSPSTAT.BF 'If SSPSTAT.BF = 0 then WEND.
Wend

End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
C.
 

ericgibbs

Joined Jan 29, 2010
15,349
hi.
I guess you know that when you initialise for a Single Reading in the
'COMPASS INITIALISATION
'SETUP COMPASS

that when you Read one value the Compass goes automatically into Power Down Mode.???

E

After changing a setting to 'single measurement READ' the program stalls just after it. I'm fairly sure it's not being READ correctly.

ESP_ 591 Jul. 14 16.27.png
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
hi.
I guess you know that when you initialise for a Single Reading in the
'COMPASS INITIALISATION
'SETUP COMPASS

that when you Read one value the Compass goes automatically into Power Down Mode.???

E

After changing a setting to 'single measurement READ' the program stalls just after it. I'm fairly sure it's not being READ correctly.
View attachment 243473
Hi E,
Yes, but I'm not sure about: Does single measurement = 'single BYTE', or could it mean 'single string of BYTEs ( BURST)?
I'm trying to get a READing like #77
C
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
him
It is explained in the d/s.
View attachment 243485
Hi E,
Ah, the much read D/S, thanks, but as mentioned over all the years, I have difficulty getting the exact meaning from them, this is why I find out by experiment instead, which takes me longer than most. I have to try all possiblities, till something happens or unless someone clarifies, which ever is the earliest.

To me it reads, that I can get a string of DATA, so I'll carry on.
Cheers, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Hi,
First, there's a question of which to pick: 'continuous measurement mode 1' 'continuous mode 2' 'single measurement mode', but leaving this asside for a while.

I moved forward in understanding how to READ DATA, which has given these results:
I'll keep moving forward slowly, using logic analyser results, as I go along.

Here's where I am today:
If anyone would like to juggle the CODE, it would be welcome. (no explanations, just CODE please) and I'll test it along with mine.
C.
Code:
''''''''''''''WaitMs 50
    wr_adr = 0x0a  'CONFIG CNTL1 reg
    wr_byte = 0x11  'WRITE CONFIG 16BIT, Single measurement mode
compss_cs = 0  'CHIP SELECT COMPASS ON
'''''''''''WaitUs 1
    SSPBUF = wr_adr
    While Not SSPSTAT.BF  'If SSPSTAT.BF = 0 then WEND (Buffer flull BIT).
    Wend
WaitUs 1
    SSPBUF = wr_byte
    While Not SSPSTAT.BF  'If SSPSTAT.BF = 0 then WEND.
    Wend
compss_cs = 1  'CHIP SELECT COMPASS OFF
'''''''''''''WaitMs 50
    rd_adr = 0x8a  '0
    rd_Byte = 0  'Dummy BYTE
    compss_cs = 0  'CHIP SELECT COMPASS ON
    data = periph_rd(rd_adr)
compss_cs = 1  'CHIP SELECT COMPASS OFF
    Hserout "READ 0x11 =17 ", #data, CrLf

compss_cs = 0  'CHIP SELECT COMPASS ON
    SSPBUF = 0x83
    For i = 0 To 5
WaitUs 1
    
        While Not SSPSTAT.BF  'If SSPSTAT.BF = 0 then WEND.
        Wend
    '''''''''''SSPBUF = 0x00
    Next i
    'WaitUs 30
compss_cs = 1  'CHIP SELECT COMPASS OFF
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
2,979
Hi,
I can see some changes needed in my CODE, which I'll work through.

I keep wondering how does anyone decide on which of the different measurement methods to choose from with AK8963 module.
1/ SINGLE measurement mode Fig 6.2
2/ SINGLE measurement mode Fig 6.3
3/ CONTINUOUS measurement MODE 1
4/CONTINUOUS measurement MODE 2

Does anyone know how to choose?
C.
 
Top