PDA

View Full Version : Yet another SERIN2 problem - Conversion from Basic Stamp



Fanias
- 22nd October 2012, 18:06
Hello all,
i need your help to convert my code from basic stamp2 sx.

I'm trying to read the frequency of an ICOM shortwave receiver.
Here is my easy working basic stamp code :


' {$STAMP BS2Sx}
' {$PBASIC 2.5}
LCDcls CON 1
I CON 254
speed CON 16624 '9600 for LCD
speedI CON 2063 '1200 for ICOM
FR VAR Byte(5)

START:

PAUSE 10
SEROUT 14,speedI,[$FE,$FE,$80,$E0,$03,$FD] 'STATUS UPDATE FREQUENCY
SERIN 14,speedI,[SKIP 5,STR FR\5] ' YES !!! the same port works for RX too !!! of course works with any other port
SEROUT 15,speed,[i,128,"F : ",HEX2 FR(1),HEX2 FR(2),HEX2 FR(3),HEX2 FR(4),HEX2 FR(5)] 'Frequency digits OK
GOTO START


And here is my NOT Working code for PIC


'''''''''''''''''''''''''''''''''''''''''''''
''''''''' PIC 18F46K22
'''''''''''''''''''''''''''''''''''''''''''''
DEFINE OSC 64

'############################################
'############# INTERNAL OSC #####################
'############################################
@ CONFIG FOSC = INTIO67
OSCCON.6 = 1 '####################
OSCCON.5 = 1 '###### 16 MHz #########
OSCCON.4 = 1 '####################
OSCTUNE.6 = 1 '#### PLL X 4 ###########
'############################################
lcds con 16468
lcdcls con 1
line1 con 128
line2 con 192
lcdp var portd.1
icp1 var portd.2
icps con 813 '33581 - 813
I con 254
fr var byte(5)

start:
pause 50 'Give some time to receiver

SEROUT2 icp1,icps,[$FE,$FE,$80,$E0,$03,$FD] 'Send this to update status
SERIN2 portd.3,icps,[SKIP 5, STR FR\5] 'Skip first 5 bytes (not needed) and store next 5 bytes to FR(1) - FR(5)

serout2 lcdp,lcds,[i,line1,"F : ",hex2 fr(1),hex2 fr(2),hex2 fr(3),hex2 fr(4), hex2 fr(5)]

goto start


The above code is not working. I get only zeros. I know that there is communication from the TX line with the receiver because I can send commands (only send) to the receiver and it responds correctly. But i cannot receive anything.
I have also tried HSERIN but the same results. And I have played with the OSC frequencies in case it was too fast for my project but no luck. In any case or OSC frequency I have tried, I can send any command I want to the receiver and it responds, but I cannot read anything from it.
That's why i also tried to use a different port for RX, but i don't think this is the problem.
I beleive basic stamp treats in other way the received bytes.

To help you more, this is what i'm expecting to receive for frequency (in hex) :
$FE,$FE,$E0,$80,$03,$FR(1),$FR(2),$FR(3),$FR(4),$F R(5),$FD

I don't need the first 5 bytes and the last byte, only FR(1) to FR (5) to display the frequency and make various calculations with the frequency digits.

Any help would be much appreciated

Thanks in advance
Fanis

Demon
- 22nd October 2012, 22:13
If it helps, these are the configs I use for my 18F46K22:


' 18F44K22 internal oscillator 64MHz

@ __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
@ __CONFIG _CONFIG2H, _WDTEN_OFF_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
DEFINE OSC 64
OSCCON = %01110000
OSCCON2 = %10000000
OSCTUNE = %11000000
INTCON2 = %10000000

ANSELA = 0
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000


Robert

Fanias
- 22nd October 2012, 23:56
If it helps, these are the configs I use for my 18F46K22:


' 18F44K22 internal oscillator 64MHz

@ __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
@ __CONFIG _CONFIG2H, _WDTEN_OFF_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
DEFINE OSC 64
OSCCON = %01110000
OSCCON2 = %10000000
OSCTUNE = %11000000
INTCON2 = %10000000

ANSELA = 0
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000


Robert

Thank you very much for the configs. Still using the old style with underscores ? (Just kidding)...
I'm not sure about all the config parameters, but in my situation it's worth to give a try first thing in the morning. I have tried everything and my code seems ok, but no results. It drives me crazy to see it working with a basic stamp and a picaxe also but not with pic... I must be missing something very simple but well hidden :)

Thanks again and i'll post my results tomorrow... Any other thought is very welcomed...
Fanis

Demon
- 23rd October 2012, 02:47
Yeah, I'm still on PBP v2.60C. I figure if it ain't broke, and I don't need any of the new features, then I'm not fixing it. :)

I'm seeing a lot of "us" (the non-experts, myself included) have problems with basic setups on the 18F PICs. They are amazing but a bit intimidating to the less knowledgeable folk if you ask me. The 18F bring so many more features and versatility (I can use 39 out of 44 pins on the 18F4xK22 series, WOOT!), but the configs can be a bit much.

I'm getting in the habit of making sure I can get my PICs to blink at 1 second interval with DT_INT before I do anything with them.

Robert
:)

Fanias
- 23rd October 2012, 11:08
I'm trying all morning and still no good results.

I tried your configs Robert and they do the same things as mine, at least I could't see any change.

I had only to remove ANSELD = 0 because nothing worked with that.

My serial lcd is connected to portd.1 and the serial TX - RX to portsD.2-3 and with ANSELD = 0 they don't work.

My code gives only zeros to the variables and I can't understand why !!
The code is very simple and straightforward and should work.

I also changed the PIC (just in case...) and I also replaced 18F46K22 with 18F4520 and the same.

LCD works OK, I can TX any byte I want and it's accepted by the receiver, but still I cannot read anything from the receiver.
I'm putting a 10 years old BS2sx with the sample code and everything works fine.

Anyone else knows what do I have to do to receive a hex string like this : ????

$FE,$FE,$E0,$80,$03,$FR(1),$FR(2),$FR(3),$FR(4),$F R(5),$FD

and i only need to read FR(1) to FR(5) ??

Any help would be very much appreciated

Fanis

Archangel
- 24th October 2012, 07:08
Just for hoots try setting up your serial Rx on a different port, say PortC, Port D has MSSP module & I THINK is also part of portE so there a bunch of tricky registers to set to make it plain old digital add to this D3 is AN23 sothere are analog issues too.