Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
The first 2x peripherals, compass and altimeter may use different methods e,g, the compass uses a DUMMY BYTE.
As the Compass is workng, initially I'll make a separate READ FUNCTION for ALTMTR, then once I get it working if they are different, is it better to modify the READ FUNCTION or make 2x different FUNCTIONS?
C
 

jjw

Joined Dec 24, 2013
823
Make first the periph_rd function and test if it can read the ID.
This could work.
Read the ID:
altmeter_cs=0
Id=periph_rd(0xD0) ' 0xD0 is the address of the id
altmeter_cs=1

Id is 0x58

Code:
Function periph_rd( adr as Byte) as Byte
SSPBUF = adr
While  not SSPSTAT.BF
Wend
SSPBUF=0 ' dummy byte
While Not SSPSTAT.BF
Wend
periph_rd=SSPBUF
End Function
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Make first the periph_rd function and test if it can read the ID.
This could work.
Read the ID:
altmeter_cs=0
Id=periph_rd(0xD0) ' 0xD0 is the address of the id
altmeter_cs=1

Id is 0x58

Code:
Function periph_rd( adr as Byte) as Byte
SSPBUF = adr
While  not SSPSTAT.BF
Wend
SSPBUF=0 ' dummy byte
While Not SSPSTAT.BF
Wend
periph_rd=SSPBUF
End Function
Hi J,
I'll give it a try, thanks.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Make first the periph_rd function and test if it can read the ID.
This could work.
Read the ID:
altmeter_cs=0
Id=periph_rd(0xD0) ' 0xD0 is the address of the id
altmeter_cs=1

Id is 0x58

Code:
Function periph_rd( adr as Byte) as Byte
SSPBUF = adr
While  not SSPSTAT.BF
Wend
SSPBUF=0 ' dummy byte
While Not SSPSTAT.BF
Wend
periph_rd=SSPBUF
End Function
Hi J,
I had put the computer to bed for the day, but I got it out again and :)
ID is shown here:
Great!
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi J,
I'm now READing the DATA registers ok, and there are no READings, apart from 2x 0x80 BYTEs, which are defaults. I've seen this pattern in my recent tests, so it appears that I have been READing ok, but results. So we are READing the DATA but it must be that the chip is not set up, so this is what I'll check next.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
How do know that reading registers is ok, when there are no readings?
Which registers are defaults and are 0x80 ?
Hi J,
On second view, I was mistaken, but we are READing the ID, so isn't your CODE READing the chip DATA?

Is my jpg helpful, or over the top?
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
Since OSH SPI, and changing to the SPBUF method of read/write, I haven't found proof of any bytes being written to the altmtr. I'm not sure about the compass, I'll check that next.

Is there an elegant code similar to the code in #1024 that can be used for write please?
C.
 

jjw

Joined Dec 24, 2013
823
Try this to write to a register and read back with periph_rd
Call periph_wr(..., ...)

You have to setup the bmp280, read the trimming parameters from 0x88 ... 0xA1 by using periph_rd, periph_wr

Code:
Proc periph_wr( adr as byte, data as byte)
SSPBUF=adr
While Not SSPSTAT.BF
Wend 
SSPBUF=data 
While Not SSPSTAT.BF
Wend 
End Proc
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Try this to write to a register and read back with periph_rd
Call periph_wr(..., ...)

You have to setup the bmp280, read the trimming parameters from 0x88 ... 0xA1 by using periph_rd, periph_wr

Code:
Proc periph_wr( adr as byte, data as byte)
SSPBUF=adr
While Not SSPSTAT.BF
Wend
SSPBUF=data
While Not SSPSTAT.BF
Wend
End Proc
Hi J,
The 0x88-0xa1 code is already in my program, but I have spoiled it, while trying to get it to work.
Could we start with this section, that comes before 0x88, please?
I have also messed with this, but I will tidy it up. e,g, I have rd_adr where it should be wr_adr.
NOTE: For my benefit, I use [ rd_adr and wr_adr ]
NOTE: The waitus 1 is for the digital analyser to work properly, it could be removed later.
C
Code:
'Initialize ALTMTR BMP280

Proc init_altmtr()

'WRITE_READ set-up registers
WaitMs 50
    wr_adr = 0x60  'WRITE 0xE0 %01100000 RESET ADDR [Is this needed?]
    wr_byte = 0xb6  '%10110110 resets BMP280 = 0x00
    WaitUs 1  '/// maybe not needed
SSPBUF = wr_adr
While Not SSPSTAT.BF
Wend
WaitUs 1
SSPBUF = wr_byte
While Not SSPSTAT.BF
Wend
End Proc                                        
   
   
   
    'Call periph_wr(wr_adr, wr_byte)

    rd_adr = 0xe0  '0
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '=0
    'Hserout "READ RST 0 ", #data, CrLf

'WaitMs 50
    rd_adr = 0xd0  'address of ID =0x58 =88
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)
    'Hserout "TEST READ ID 0x58 88  ", #data, CrLf

'WaitMs 50
    wr_adr = 0x74  'WRITE 0xF4 %01110100 Control CTRL_MEAS reg addr
    wr_byte = 0x5f  '%01011111 T/ON P/ON 't_x2 px16 Normal Mode
    'Call periph_wr(wr_adr, wr_byte)
'WaitMs 50
    rd_adr = 0xf4  '95
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '95
    Hserout "READ 0x74 0x5F 95 ", #data, CrLf

'WaitMs 50
    wr_adr = 0x75  'WRITE 0xF5 %01110101 Control CONFIG reg addr
    wr_byte = 0x1c  '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6
    'Call periph_wr(wr_adr, wr_byte)
'WaitMs 50
    rd_adr = 0xf5  '28
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '28
    Hserout "READ 0x75 0x1c 28 ", #data, CrLf
   
'End Proc
Proc rd_init_altmtr()  'BMP280 READ Compensation parameters that have just been WRITTEN.
For i = 0 To 23
    rd_Byte = b(i)
    Hserout "Comp PAR =", #b(i), CrLf  '?????????????COMP
Next i
End Proc
 

jjw

Joined Dec 24, 2013
823
Hi J,
The 0x88-0xa1 code is already in my program, but I have spoiled it, while trying to get it to work.
Could we start with this section, that comes before 0x88, please?
I have also messed with this, but I will tidy it up. e,g, I have rd_adr where it should be wr_adr.
NOTE: For my benefit, I use [ rd_adr and wr_adr ]
NOTE: The waitus 1 is for the digital analyser to work properly, it could be removed later.
C
Code:
'Initialize ALTMTR BMP280

Proc init_altmtr()

'WRITE_READ set-up registers
WaitMs 50
    wr_adr = 0x60  'WRITE 0xE0 %01100000 RESET ADDR [Is this needed?]
    wr_byte = 0xb6  '%10110110 resets BMP280 = 0x00
    WaitUs 1  '/// maybe not needed
SSPBUF = wr_adr
While Not SSPSTAT.BF
Wend
WaitUs 1
SSPBUF = wr_byte
While Not SSPSTAT.BF
Wend
End Proc                                       
  
  
  
    'Call periph_wr(wr_adr, wr_byte)

    rd_adr = 0xe0  '0
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '=0
    'Hserout "READ RST 0 ", #data, CrLf

'WaitMs 50
    rd_adr = 0xd0  'address of ID =0x58 =88
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)
    'Hserout "TEST READ ID 0x58 88  ", #data, CrLf

'WaitMs 50
    wr_adr = 0x74  'WRITE 0xF4 %01110100 Control CTRL_MEAS reg addr
    wr_byte = 0x5f  '%01011111 T/ON P/ON 't_x2 px16 Normal Mode
    'Call periph_wr(wr_adr, wr_byte)
'WaitMs 50
    rd_adr = 0xf4  '95
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '95
    Hserout "READ 0x74 0x5F 95 ", #data, CrLf

'WaitMs 50
    wr_adr = 0x75  'WRITE 0xF5 %01110101 Control CONFIG reg addr
    wr_byte = 0x1c  '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6
    'Call periph_wr(wr_adr, wr_byte)
'WaitMs 50
    rd_adr = 0xf5  '28
    rd_Byte = 0  'Dummy BYTE
    'data = periph_rd(rd_adr)  '28
    Hserout "READ 0x75 0x1c 28 ", #data, CrLf
  
'End Proc
Proc rd_init_altmtr()  'BMP280 READ Compensation parameters that have just been WRITTEN.
For i = 0 To 23
    rd_Byte = b(i)
    Hserout "Comp PAR =", #b(i), CrLf  '?????????????COMP
Next i
End Proc
You have commented out periph_rd and periph_wr.
You don't have to set separately rd_adr= 0xF5, rd_byte=0 (dummy byte) The dummy byte is included in the read function.
data=periph_rd(0xF5) is enough.
How did you get b(I)?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
You have commented out periph_rd and periph_wr.
You don't have to set separately rd_adr= 0xF5, rd_byte=0 (dummy byte) The dummy byte is included in the read function.
data=periph_rd(0xF5) is enough.
How did you get b(I)?
Hi J,
The section that I included in #1032 comes before the b(i) [ i not 1 ] so I would like to 'do' that section first. The 1st register [ Proc init_altmtr() ] is reset, and I think we've got it to read write and read. "data=periph_rd(0xF5) is enough" is what I used for this.

The commented out parts are some of the tries I have done over the weeks, and will be tidied up once it is working better, they remind me what not to do ;)
C.
 

jjw

Joined Dec 24, 2013
823
Take now the old working BMP280 program and replace all
SpiSend adr
SpiReceive data
-----> data= periph_rd(adr)

SpiSend(adr)
SpiSend(data)
------> call periph_wr(adr,data)

Remove all SW SPI settings, registers and pins for clock, CS, SDI etc.

That should be enough to get a working program with HW SPI.
Maybe some tidying later.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Take now the old working BMP280 program and replace all
SpiSend adr
SpiReceive data
-----> data= periph_rd(adr)

SpiSend(adr)
SpiSend(data)
------> call periph_wr(adr,data)

Remove all SW SPI settings, registers and pins for clock, CS, SDI etc.

That should be enough to get a working program with HW SPI.
Maybe some tidying later.
Hi J,
Take now the old working BMP280 program and replace all
SpiSend adr
SpiReceive data
-----> data= periph_rd(adr)

I had done that a week or so ago, I think after you first suggested it but I ammended it slightly using rd_adr and wr_adr, so I could read it more correctly.
I 'did' one wr to register and then rd, which is succesful, now to go down the list.
I tried with a helpful mate today, but the radio link failed so I'll try again here on my own.
Cheers, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,837
Hi,
I've had some success, but a bit unreliable.
with this code, it sometimes reads and some times doesn't. I've tried moving the hserout, farther down the program, and it is most likely to work.
Generally, what causes this type of thing?
C
Code:
WaitMs 50
    wr_adr = 0x74  'WRITE 0xF4 %01110100 Control CTRL_MEAS reg addr
    wr_byte = 0x5f  '%01011111 T/ON P/ON 't_x2 px16 Normal Mode
    Call periph_wr(wr_adr, wr_byte)
'WaitMs 50
    
    ctrl_meas = periph_rd(0xf4)
    Hserout "ALT READ CTRL_MEAS 95  =", #ctrl_meas, CrLf, CrLf
 
Top