SPI PIC 18F4620 and BMP280 (In Oshonsoft)

jjw

Joined Dec 24, 2013
823
Hi,
Previously we have succesfully got 2x PICs to 'talk' to each other via SSPBUF, now I'm trying to get PIC1 to READ a peripheral's REGISTERS, via SSPBUF, but so far haven't succeded.
I'm starting to get mixed up, but can someone try this OSH SPI program in their simulator and see if it get's past HSEROUT please?
C
I don't know about HSEROUT, but you mix Oshonsoft software
SPI functions and HW SPI.

You need first to setup the HW SPI.
To read from a register, write the register address then write a zero byte and SSPBUF should have the data from that address.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
I don't know about HSEROUT, but you mix Oshonsoft software
SPI functions and HW SPI.

You need first to setup the HW SPI.
To read from a register, write the register address then write a zero byte and SSPBUF should have the data from that address.
Hi J and E,
SW and HW confuse me, so I use the terms the OSH SPI method and SSPBUF method.

As I couldn't get the SSPBUF method to work READing Registers, I thought I would get and old working program (mixed) running, then make a second LOOP, where I try SSPBUF. I appreciate, that anyone who can program reading this, may be puzzled, but I have to work in any way I can get some results.

Once I get the old working program going again (Upgrade issues etc) I have a LINK from a while back, that goes through it all and I'm sure, your above suggestion will be there: https://forum.allaboutcircuits.com/...and-bmp280-in-oshonsoft.162449/?cb=1621675780

I note 'E's link, which I'll read if all else fails.

(I think it is the above ZERO BYTE that's the problem)

Thanks, and onward.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
Previously we have succesfully got 2x PICs to 'talk' to each other via SSPBUF, now I'm trying to get PIC1 to READ a peripheral's REGISTERS, via SSPBUF, but so far haven't succeded.
I'm starting to get mixed up, but can someone try this OSH SPI program in their simulator and see if it get's past HSEROUT please?
C
hi C,
Checking the asm code, shows that the correct code has been compiled.
When it stops and I set the TXI bit using the IDE , the program just runs thru the TEST message, but no UART print out.
Ask Vlad.
E
Hi E,
I've just emailed Vlad again, with both of your images. (No name)
C
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Don't worry about Vlad knowing who posted those images, in the early days we cooperated on creating external models for the IDE.

E
BTW: that Hser test works fine with 18F4620 but not the 'K' version
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Don't worry about Vlad knowing who posted those images, in the early days we cooperated on creating external models for the IDE.

E
BTW: that Hser test works fine with 18F4620 but not the 'K' version
Hi E,
I didn't know that, excellent!
Just had a thought! Vlad's working on an endless project, like me:)

He's just asked which PIC I'm using and a short CODE.
I sent yours from #178
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I just re-read through this (long) thread, as 'dummy byte' is rattling round my head.

Probably said quite a few times, but in #12 is this:
For i= 0 to 23
adr=0x88+i
SSPBUF=adr
Call Spi_wr_rd() ' send address
SSPBUF = 0 '(I haven't been adding this)
Call Spi_wr_rd() ' send dummy byte to read from address
data= SSPBUF
b(i) = data
next i
(NOTE: I remember separate SPI_RD and SPI_WR)
Sorry it's taken you all so much effort! I've visualised the colour register block with it's 3x READ BYTES and thought of 'dummy byte' but never connected them.
I hope I've got it this time? Let's see what happens next.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Checking the asm code, shows that the correct code has been compiled.
When it stops and I set the TXI bit using the IDE , the program just runs thru the TEST message, but no UART print out.
Ask Vlad.
E
Hi E,
Can you explain what you did here to find the error please?
Is the arrow and IDE indicator, or did you add it?
C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Use Tools/ Breakpoint Manager
The Break point window display 'Arrow' will show you the progress of the programs execution [ bit like the Basic tracking option]

If it comes to perpetual loop its easy to see.

BTW: If you use this option you can add a Break instruction in your program code, and the display will stop your breakpoint.

E
ESP_ 366.png
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Use Tools/ Breakpoint Manager
The Break point window display 'Arrow' will show you the progress of the programs execution [ bit like the Basic tracking option]

If it comes to perpetual loop its easy to see.

BTW: If you use this option you can add a Break instruction in your program code, and the display will stop your breakpoint.

E
View attachment 239729
Hi E,
That's interesting!
Armed with an ascii chart, I could see where TEST is in the ASM. Nicely visual. I wonder if there's any chance that I could follow it through and learn ASM:eek:C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi,
When you compile a Basic program the OSH IDE creates a annotated ASM file, alongside all the Basic commands.

You could write that missing Serial routine section in ASM, within the Basic code.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi,
When you compile a Basic program the OSH IDE creates a annotated ASM file, alongside all the Basic commands.

You could write that missing Serial routine section in ASM, within the Basic code.

E
Hi E,
I can't write ASM, so is it possible to copy and paste that section from a compiled 18LF4620 program?
C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Post a short Basic program that has Hser, see what we can do.
It maybe that the IDE simulator will not respond, even if it works in an actual PIC.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Post a short Basic program that has Hser, see what we can do.
It maybe that the IDE simulator will not respond, even if it works in an actual PIC.
E
Hi E,
I have previous 18LF4620 programs working with long programs, and always used HSEROUT for feedback.

Tomorrow, I'll try the latset problem 18F46K20 program (shortish) and the same program, but set to 18LF4620 then compare the two compiled ASM programs.
C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Don't waste your time.
Spent a couple of hours trying to get the IDE to respond to the ASM version, it will not.
When it runs it still hangs up at the same point in the code as the basic program.

Also it keeps calling Library files from the Code.

Why are you using the 'K' version for testing your programs...?

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Don't waste your time.
Spent a couple of hours trying to get the IDE to respond to the ASM version, it will not.
When it runs it still hangs up at the same point in the code as the basic program.

Also it keeps calling Library files from the Code.

Why are you using the 'K' version for testing your programs...?

E
Hi E,
I hope I'm understanding all this correctly? It is mind baffling!
Anyway, Vlad said
"For example, UART Module is simulated for the 18F4520 device
in PIC18 Simulator IDE, but not for the 18F46K20 you selected."

so it won't simulate, but LIVE it works.
I tried an previous Program and today it is working:

I think one interpretation problem is that I am READing multiple peripherals, but they appear to be only one, as there is a SWITCH between them.

Here is the working (at the moment) program. you sould see there are 2x LOOPs. (Sorry for working in my unprofessional way) The first LOOP uses the 'old' OSH SPI method and I hope to see if I can READ the ALTIMETER peripheral using the SSPBUF method.

This may be a waste of time, but I have no alternative.

C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,

Why are you using the 'K' version for testing your programs...?

E
Hi E,
If you compare 18F4520, 18F4620, 18LF4620 and 18F46K20 they are pretty similar. I've use all of them, and each has it's own problem. Memory, speed and the latest is voltage. The 18F46K20 is 1.8V-3.6V the others are 2V-5.5V this has caused a problem, so that's why. I test them on a complete PCB with connections for peripherals 3x Voltage regulators, all changed over the years.

I'm sure I'll have problems till Vlad updates the 18F46K20.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi.
What I am saying is it will not work in the IDE OSH simulator.!:)
even when coded in ASM.
E
Hi E,
Yes, I follow. I have been unable to simulate for a while now, apart from sections. e,g, there are 2x PIC talking to each other, where quite a sophisticated simulator would be needed.
Thanks for taking time to test it all, much appreciated.
(I've still got to compare 2x different PIC programs in ASM)
Cheers, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
Using one of my programs, I compiled it twice. 1x set to 18F4620 1x set to 18F46K20, then put both ASM files in a comparison program, that high-lights the differences. To my surprise they are completely different.
I was unable to test 18LF4620, as it's not listed in OSH
I can't read ASM CODE, but I can see trends in it, and will try to pick it up, if I can.

Would anyone like me to post the comparison? I think I will need to join sections into a JPG.
C.
 
Last edited:
Top