PDA

View Full Version : HSERIN HSEROUT - Baud rate help



George
- 9th September 2010, 05:48
Am having significant problems trying to transmit some data.

I'm using some wireless transceivers as found here: http://www.littlebirdelectronics.com/products/Wireless-RF-Transceiver-431%252d470MHz-GFSK-Data-Transfer-x-2.html

they are supposed to be 'transparent' to and should just replace a cable. They are set up by default to be 9600bps.

I've hooked them up to a couple of micros and run a scope on them. I cant really figure out whats going on.

The number I'm sending out is 100 so = 1100100

The input to the transmitter & receiver output timings listed below
(first column transmitter input - second column receiver output)
L 1.25ms L 0.93ms
H 0.42ms H 0.1ms
L 0.83ms L 0.82ms
H 0.83ms H 0.2ms
L 0.42ms L 0.42ms

I figure either the output baud of my PIC isnt 9600 so the transmission is getting skewed or maybe it's inverted? The line on both starts and finished high.

Have done comms just a couple of times before but never fully grasped the concepts.

transmitter code:


'pic16f722

DEFINE OSC 4
DEFINE HSER_BAUD 9600 'Set Baud rate to 9600bps
DEFINE HSER_BITS 9 'Set to 9 bit mode
DEFINE HSER_EVEN 1 'Set Even Parity
DEFINE HSER_CLROERR 1 'Clear overflow error automatically
DEFINE HSER_TXSTA 20h 'Set receive register to TX en
define HSER_SPBRG 25
DEFINE HSER_SPBRGH 1

INTCON = 0 'Disable interrupts
TRISB = %00000100 'SET PORTB RB2(RX) as input, others to OUTPUT
TRISA = %00000000 'SET PORTA AS OUTPUTS

ADCON0 = %0110010 'disable
ADCON1 = %1000000

TRISA= %00000000 'Set all to outputs
ANSELA= %00000000 'Set all to digital
TRISB= %00000111 'set buttons as input
ANSELB= %00000000 'all digital
TRISC= %00000000 'Set PortC all outputs
SSPCON= 0 'disable spi
CPSCON0 = %00001101 'Cap sense off
porta = 63
PAUSE 1000

LeftBtn Var PORTB.1
RiteBtn Var PORTB.0
StopBtn VAR PORTB.2
RadioEn var PortC.5
B0 VAR BYTE
TXdata var byte

pause 1000
clear
B0 = 1

startloop:
pause 500
b0 = b0*2
porta = b0
if b0 > 60 then start
goto startloop

radioen = 1

Start:

txdata = 100
pause 100

hserout [txdata]

goto start


and receiver code:


@ __config _CONFIG1, _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _MCLR_OFF
'pic16f88
ADCON0 = %00000000 'ADC Disabled
CMCON = 7
ANSEL = 0

DEFINE OSC 4
DEFINE HSER_BAUD 9600 'Set Baud rate to 9600bps
DEFINE HSER_BITS 9 'Set to 9 bit mode
DEFINE HSER_EVEN 1 'Set Even Parity
DEFINE HSER_CLROERR 1 'Clear overflow error automatically
DEFINE HSER_RCSTA 90h 'Set receive register to receiver en
define HSER_SPBRG 25
DEFINE HSER_SPBRGH 1

ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF
INTCON = 0 'Disable interrupts
TRISB = %00000100 'SET PORTB RB2(RX) as input, others to OUTPUT
TRISA = %00000000 'SET PORTA AS OUTPUTS

'Variables
MtrPwr Var PortA.1
ServoEn VAR PortB.3 '0 = enabled
RadioEn VAR PortB.4 '1 = enabled
RXdata var byte 'received data frm tx
b0 var byte

PortA = 0
PortB = 0
ServoEn = 1
radioen = 1

BCMDATA VAR BYTE[12] 'Define BCMAADATA as a byte array (12 Bytes)
Count1 VAR BYTE 'Define Count1 as a byte variable (Used in For/Next Loops)
CheckSum VAR BYTE 'Define CheckSum as a byte variable

pause 1000

for b0 = 0 to 20
toggle mtrpwr
pause 100
next b0
mtrpwr = 0
clear

Commloop: 'Start of Communications Loop

HSERIN [Rxdata] 'receive data

if rxdata = 100 then
mtrpwr = 1
pause 10000
else
mtrpwr = 0
endif

pause 500

goto commloop


I would really appreciate some help from you wonderful people, I've just started back into PBP and every aspect of my first project back is turning to custard. Many Thanks in advance

George
- 9th September 2010, 06:09
I just noticed in the transmission the shortest bit is 0.42ms, that equates to around 2400bps and in the receiver output the shortest is 0.1ms which equates to 10,000bps - tho I didnt measure it that accurately so probably 9600. If it works like that - why is my PIC sending out data at 2400bps?

ScaleRobotics
- 9th September 2010, 14:42
It looks like your transmitter is set to 2400, but your receiver is set for 9600 baud.

check out:


DEFINE HSER_TXSTA 20h 'Set receive register to TX en
define HSER_SPBRG 25
DEFINE HSER_SPBRGH 1


I like using PicMultiCalc. It can be found here: http://www.picbasic.co.uk/forum/content.php?r=159-New-PIC-Utility.-PICMultiCalc

Then I can just paste it into my code. Here is one for 2400 baud, and one for 9600 baud.


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

George
- 10th September 2010, 02:04
Thanks - it works a treat now! Really appreciate your help. That Mister E is a clever fello

George
- 15th September 2010, 01:43
The PIC16f722 was doing funny things, in desperation I threw it away and went back to the trusty 16F88 however this is not working for me either.

The PicKit 3 I bought was driving me mad also, so it's back to the ETT programmer and PicKit 2 software.

It compiles and assembles ok, but it will not program. The programmer says "Verification of Configuration Failed" It programs fine if I get rid of anything to do with HSEROUT the defines and the command.

But the instant I bring in an HSEROUT command it will fail.

Here's the code:



@ __config _CONFIG1, _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF & _MCLR_OFF
'pic16f88
ADCON0 = %00000000 'ADC Disabled
DEFINE OSC 4
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF
INTCON = 0 'Disable interrupts
TRISB = %00001111 'SET PORTB RB2(RX) as input, others to OUTPUT
TRISA = %00000000 'SET PORTA AS OUTPUTS

porta = 63
PAUSE 1000

'LeftBtn Var PORTB.1
'RiteBtn Var PORTB.3
'StopBtn VAR PORTB.0
'RadioEn var PortB.4

B0 VAR BYTE
B1 var byte
B2 var byte
TXdata var byte
Direction var byte
LEDPtrn var byte
WakeVar var byte
MtrPwr var bit

pause 1000
clear

porta = 0

start:
txdata = 100
hserout [txdata]
pause 1000
goto start


I'm going completely nuts over this and I think I'm about to get fired for being so useless. Please help

mackrackit
- 15th September 2010, 05:52
I do not know what is going on with the HSEROUT but you may want to correct something else. Who knows, maybe it will solve the other.

RA5 can only be an input. You have.
TRISA = %00000000 'SET PORTA AS OUTPUTS

Then this
porta = 63 = 00111111

malc-c
- 15th September 2010, 08:05
On the 18 pin device it appears that RA7 is also input only !

http://ww1.microchip.com/downloads/en/devicedoc/30487c.pdf

Also, and whilst no expert on your settings you have


TRISB = %00001111 'SET PORTB RB2(RX) as input, others to OUTPUT
TRISA = %00000000 'SET PORTA AS OUTPUTS

porta = 63
PAUSE 1000

'LeftBtn Var PORTB.1
'RiteBtn Var PORTB.3
'StopBtn VAR PORTB.0
'RadioEn var PortB.4


you have set PORTB as output apart from RB2 but appear to have buttons which are normally inputs ( taking pin high or low) on RB1, RB3, RB0 and RB4 ?, but appear to have set it correctly with TRISB = %00001111