PDA

View Full Version : Serin general question



Seahound1
- 30th September 2011, 14:16
I am using 2 16F887a's to communicate data via RS485 in an ROV project. Sending data from the ROV to the surface works fine, but I can't get the ROV to recieve data for the light switch command (I know the comm's are working because I am using a Pololu servo controller to operate the thrusters). Can some one tell me what is wrong with the following code? The processor hangs striaght after the I2C command.
Light_pos =0
Main:
i2cread SDA,SCL,$C0,2, 'get data from the compass
lcdout $fe, 1,"Heading ",DEC BEARING/10,223
SEROUT PORTC.6,T9600,["H",bearing.Highbyte,bearing.lowbyte] 'transmit compass data to the surface
[B]Serin PORTC.7,T9600,200,read_adc,["L"],Light_val ' test for light status from the surface
read_adc:
ADCIN 0,AD0 ' read AD's for temp, gyro and pressure
AD0 = (AD0*10)/quanta
LCDOUT $fe, $C0
LCDOUT DEC AD0
AD0=0

Mike2545
- 30th September 2011, 16:42
Do you have Include "modedefs.bas" somewhere near the beginning of your code?

Also check out the SERIN2 command.

Charles Linquis
- 30th September 2011, 16:54
Why in the world would you use SERIN/SEROUT when you have hardware serial ports available?

Seahound1
- 30th September 2011, 19:06
Yes the "modedefs.bas" has been included. Sorry I don't get the comment about hardware ports?
The LCD stuff is in there jsut so that I can see what is going on. If the Serin is removed (commented out) the program runs fine???

Charles Linquis
- 30th September 2011, 20:04
The chip you are using has a EUSART = Hardware serial port.

You can use HSERIN and HSEROUT for your communications. You can read PIR1.5 (at least that is what it is in 18F chips), you have serial port interrupts, you can transfer a byte and move on.....

Things work so much better when you use the hardware that Microchip has provided.

Seahound1
- 1st October 2011, 21:52
Understood thanks ref the HSERIN....I will give it a try. The strange thing is it works fine on the surface control unit. The other thing is I am using RS485 chips directly.
Will give it a try and report back....when normal work dosen't get in the way:)

Seahound1
- 21st October 2011, 14:28
I could not get the HSERIN to work....probably timing and RCV stack overflowing. I can't see how I can use the interupt because I don't want to interupt the program.....the motor/thruster commands must take priority. However I did fianlly manage to get the SERIN/SEROUT working, it was a stupid mistake in my program - the jump to statement was pointing to the wrong place. Would like to use the HSERIN though at some point I think it would give better control and think it would also allow me to reduce one of the additinal PCB's.
Thanks for your help

cncmachineguy
- 21st October 2011, 15:23
maybe this will help?
http://www.picbasic.co.uk/forum/showthread.php?t=14009