Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,838
s2m should be an array of bytes, not words as it is now.
Hi J,
I'm an experimenter, so after trying BYTES for a couple of days, I tried WORDS. It was interesting to me to see 2x BYTEs arrive. While as WORD I tried larger WORD numbers with '9' in them and that section showed empty, as the BYTE did.
C
 

jjw

Joined Dec 24, 2013
823
Hi J,
I'm an experimenter, so after trying BYTES for a couple of days, I tried WORDS. It was interesting to me to see 2x BYTEs arrive. While as WORD I tried larger WORD numbers with '9' in them and that section showed empty, as the BYTE did.
C
It has to be bytes, because you write to SSPBUF which is 8 bits.
You don't know what happens, when a word is written to SSPBUF.
It may write the high byte, low byte or nothing.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,838
It has to be bytes, because you write to SSPBUF which is 8 bits.
You don't know what happens, when a word is written to SSPBUF.
It may write the high byte, low byte or nothing.
Hi J,
It's all BYTEs now, and back to the missing '9'
C.
 

jjw

Joined Dec 24, 2013
823
What happens, when the master is sending and you write to SSPBUF in the slave?
You could synchronize the master and the slave:

Main:
-- Master sends 7, slave waits until it gets 7, then it puts s2m(0) into SSPBUF.
--Master sends dummy byte and gets 8 ( s2m(0) =8 )
--Master sends 7, slave waits .... puts s2m(1) into SSPBUF
--Master sends dummy byte and gets 9 ( s2m(1) =9 )
Goto Main

Both master and slave looping between main --- goto main
 

Thread Starter

camerart

Joined Feb 25, 2013
3,838
What happens, when the master is sending and you write to SSPBUF in the slave?
You could synchronize the master and the slave:

Main:
-- Master sends 7, slave waits until it gets 7, then it puts s2m(0) into SSPBUF.
--Master sends dummy byte and gets 8 ( s2m(0) =8 )
--Master sends 7, slave waits .... puts s2m(1) into SSPBUF
--Master sends dummy byte and gets 9 ( s2m(1) =9 )
Goto Main

Both master and slave looping between main --- goto main
Hi J,
I'm trying all sorts of things!
First I changed the ARRAY to a single BYTE.
The MASTER should show what it is about to send in M2S. (Is this correct?) With no SLAVE involved.
At this point it shows [FROM MASTER= 0-8] but never '9' or '10'
If I increment M2S, when it gets to '11' it shows [0B] 12=[0C] 25=[19] 255=[Y] with dots.

Does this give any clues?
C
 

jjw

Joined Dec 24, 2013
823
Why the master should show what it intends to send?
Just send it.

What do you want to do?
When master sends 0 it gets back s2m(0), when it sends 1 it gets back s2m(1) etc. ??
 

Thread Starter

camerart

Joined Feb 25, 2013
3,838
Why the master should show what it intends to send?
Just send it.

What do you want to do?
When master sends 0 it gets back s2m(0), when it sends 1 it gets back s2m(1) etc. ??
Hi J,
I've spent days trying things as you suggest, but there seems to be a problem with '9' for some reason, so I've gone to basics with BYTES instead of ARRAYS, and as a test, I'm seeing what MASTER is about send first. I can see what it's about to send at FROM MASTER=, so with no SPI or SLAVE I think I've proved that there is some other issue.
I will do any tests you suggest.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,838
Hi,
I wrote a short BYTE TEST program, the results are the same. everything but '9'??
C
Code:
'18f46K20 32mhz XTL BASE BYTE TEST
'----------- SYSTEM CONFIG  --------------------
'PIC Config
Define CONFIG1L = 0x00  'not used
Define CONFIG1H = 0x06  '8mHz XTL x4 =32Mhx
Define CONFIG2L = 0x1e  '? brownout/ power
Define CONFIG2H = 0x00  'defaults cleared
Define CONFIG3L = 0x00  'defaults cleared
Define CONFIG3H = 0x89  '89 PORTB as DIG IN-OUT 'MCLR pin enabled
Define CONFIG4L = 0x80  'no debug?
Define CONFIG4H = 0x00  'not used
Define CONFIG5L = 0x0f  'default
Define CONFIG5H = 0xc0  'default
Define CONFIG6L = 0x0f  'default
Define CONFIG6H = 0xe0  'default with a don't care loc added
Define CONFIG7L = 0x0f  'default
Define CONFIG7H = 0x40  'default

'OSH config
Define SINGLE_DECIMAL_PLACES = 2
Define CLOCK_FREQUENCY = 32
'Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

Disable High
Disable Low

'Clear all PORTS
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
'Initialise PINS As On/OFF
LATA = 0
LATB = 0
LATC = 0
LATD = 0
LATE = 0

'Set PINS as IN/OUT
TRISA = %11101111  '4=pic4431_cs
TRISB = %11111111
TRISC = %11011111  '5=MOSI 4=MISO 3=SCK
TRISD = %11111111  '4=HC-12_CS
TRISE = %11111011  '3=MCLR 2=RLED 1=DRDY

ANSEL = %00000000  '7-5=RE0-2, 4-0=RA5-0'[ANALOG SELECT]?????????????????
ANSELH = %00000000  '4-0=RB0,4,1,3,2 (PBADEN of CONFIG3H 0=0)??????????

Symbol rled = LATE.2

RCON.IPEN = 1  'this MUST be included???????????

'START UP LEDS - show the board is running
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000

Dim m2s As Byte  'MASTER to SLAVE
'Dim m2s(2) As Byte

'OPEN UART
Hseropen 9600  'set hardware usart speed to 9600 baud
WaitMs 1000

MAIN:

m2s = 9

Hserout "BYTE TEST=  ", m2s, CrLf  'Show DATA to SEND<<<<<<<<<<<<<<<<<<
WaitMs 20

Toggle rled  'tell the world something has happened
WaitMs 100
Goto MAIN

End
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,838
Hi,
I asked the Microchip forum about this also, and was sent a MAIN LOOP with a 20 STEP sequence, that gave out this result:

It looks interesting, as it misses '9' but also steps 2 at a time.
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,838
Strange!
Could it be terminal/Comport setting?
Hi J,
This is also a suggestion by the Microchip forum!
Could it be that the SPI MASTER/SLAVE, is working correctly, but the results are lying?

I'm using HSEROUT, as you can see, but from the past, there were errors here to. My mate is trying to write a none OSH one, we are calling it DSEROUT after his name initial.
What do you think?
C
 

sagor

Joined Mar 10, 2019
1,050
Post the whole test code.... You are getting all the numbers, but in a funny order. Could be how the byte is defined, how the test loop is written, etc.
 

jjw

Joined Dec 24, 2013
823
It is possible that the SPI worked correctly.

You could test Hserout and Serout in the simulator.
Is the terminal connected via radio link?
Check the radio setup.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,838
Post the whole test code.... You are getting all the numbers, but in a funny order. Could be how the byte is defined, how the test loop is written, etc.
Hi S,
Here it is, but read below first:
Code:
'18f46K20 32mhz XTL BASE BYTE TEST
'----------- SYSTEM CONFIG  --------------------
'PIC Config
Define CONFIG1L = 0x00  'not used
Define CONFIG1H = 0x06  '8mHz XTL x4 =32Mhx
Define CONFIG2L = 0x1e  '? brownout/ power
Define CONFIG2H = 0x00  'defaults cleared
Define CONFIG3L = 0x00  'defaults cleared
Define CONFIG3H = 0x89  '89 PORTB as DIG IN-OUT 'MCLR pin enabled
Define CONFIG4L = 0x80  'no debug?
Define CONFIG4H = 0x00  'not used
Define CONFIG5L = 0x0f  'default
Define CONFIG5H = 0xc0  'default
Define CONFIG6L = 0x0f  'default
Define CONFIG6H = 0xe0  'default with a don't care loc added
Define CONFIG7L = 0x0f  'default
Define CONFIG7H = 0x40  'default

'OSH config
Define SINGLE_DECIMAL_PLACES = 2
Define CLOCK_FREQUENCY = 32
'Define SIMULATION_WAITMS_VALUE = 1  'Comment in for SIM out for PIC

Disable High
Disable Low

'Clear all PORTS
PORTA = 0
PORTB = 0
PORTC = 0
PORTD = 0
PORTE = 0
'Initialise PINS As On/OFF
LATA = 0
LATB = 0
LATC = 0
LATD = 0
LATE = 0

'Set PINS as IN/OUT
TRISA = %11101111  '4=pic4431_cs
TRISB = %11111111
TRISC = %11011111  '5=MOSI 4=MISO 3=SCK
TRISD = %11111111  '4=HC-12_CS
TRISE = %11111011  '3=MCLR 2=RLED 1=DRDY

ANSEL = %00000000  '7-5=RE0-2, 4-0=RA5-0'[ANALOG SELECT]?????????????????
ANSELH = %00000000  '4-0=RB0,4,1,3,2 (PBADEN of CONFIG3H 0=0)??????????

Symbol rled = LATE.2

RCON.IPEN = 1  'this MUST be included???????????

'START UP LEDS - show the board is running
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000

Dim m2s As Byte  'MASTER to SLAVE
'Dim m2s(2) As Byte

'OPEN UART
Hseropen 9600  'set hardware usart speed to 9600 baud
WaitMs 1000

MAIN:

m2s = 9

Hserout "BYTE TEST=  ", m2s, CrLf  'Show DATA to SEND<<<<<<<<<<<<<<<<<<
WaitMs 20

Toggle rled  'tell the world something has happened
WaitMs 100
Goto MAIN

End
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,838
It is possible that the SPI worked correctly.

You could test Hserout and Serout in the simulator.
Is the terminal connected via radio link?
Check the radio setup.
Hi J,
I think the radio is fine.
Yes, the terminal is radio connected. The radio will be used for radio control later (If I ever finish:) )
HSEROUT is not supported by Oshonsoft, so doesn't work in the SIM.
SEROUT works in SIM, but not live.
I also have a listening radio, and there's no sound.

EDIT: Corrected.
C
 

Attachments

Last edited:
Top