HSEROUT Newbie question/problem


Closed Thread
Results 1 to 13 of 13
  1. #1
    Mark Scotford's Avatar
    Mark Scotford Guest

    Default HSEROUT Newbie question/problem

    I am trying to use serial comms to a PC for the first time. I am using a known good PCB from another project which has a MAX 232 chip for the RS232 I/O. The processor is a 17C756A running at 10Mhz and I am using the Serial communicator in Micro Code Studio + to see what coming out of the port. I am trying to use 2400 Baud 8N1 (which serial communicator is set up to) for no other reason than it was the first one I thought of, but I have tried others. Basically the project is a Temperature Data Logger, which will have 8 inputs and as each sensor is read in turn, squirts the value read out of the Logger to a PC, most probably running Excel. I have used ADCIN before on another project and I know I can get that to work (if its wrong in the example shown, don't worry about that I will sort it later) my problem now is to get the value stored in variable B3, out of the serial port and into my PC, at the moment, serial communicator shows characters coming out, but they are garbage and some of the time the characters change. I have forced B3 to a known value for testing purposes, so B3 should be reading as 123. I have calculated the SPBRG value from the Microchip Data Sheet AN774 as being (10000000 / (64 x 2400 =153600) -1 =64.104166. There is no High Speed option on the PIC17C756A according to the data sheet, so BRGH = 0. Incidentaly the LCD display is working fine.

    Here is a listing from what I have so far:-

    'FW1-0DLV1-0 09/07/2K6
    'Was MCV2-2FW1-2

    'A4 P43 =RS232 RX-1 Input
    'A5 P42 =RS232 TX-1 Output
    'B0 P59 ="Serial" LED Output
    'B1 P58 ="Coin" LED Output
    'B2 P54 ="Error" LED Output
    'B7 P48 =Beeper Output
    'D0 P11 =Display D0 Output
    'D1 P10 =Display D1 Output
    'D2 P9 =Display D2 Output
    'D3 P8 =Display D3 Output
    'D4 P4 =Display D4 Output
    'D5 P6 =Display D5 Output
    'D6 P5 =Display D6 Output
    'D7 P4 =Display D7 Output
    'E0 P12 =Display RS Output
    'E1 P13 =Display R/W Output
    'E2 P14 =Display E Output
    'F0 P28 =AN4=Input
    'F1 P27 =AN5=Input
    'F2 P26 =AN6=Input
    'F3 P25 =AN7=Input
    'G0 P34 =AN3=Input
    'G1 P33 =AN2=Input
    'G2 P32 =AN1=Input
    'G3 P31 =AN0=Input

    B0 VAR BYTE
    B1 VAR BYTE 'General Purpose Counter
    B2 VAR BYTE 'Value Of ADC Channel
    B3 VAR BYTE 'ADC Channel Value after processing
    B21 VAR BYTE
    B22 VAR BYTE
    B26 VAR BYTE


    clear

    TRISB = %01100000 'Sets Pins to Input or Output
    TRISC = %11111100 'Sets Pins to Input or Output
    TRISD = %00000000 'Sets Pins to Input or Output
    TRISE = %11111000 'Sets Pins to Input or Output
    TRISF = %01011111 'Sets Pins to Input or Output
    TRISG = %11111111 'Sets Pins to Input or Output

    PORTE.1 = 0
    PORTB.7 = 1

    DEFINE OSC 12
    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 0
    DEFINE LCD_RWREG PORTE
    DEFINE LCD_RWBIT 1
    DEFINE LCD_RSREG PORTE
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTE
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 8
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    ADCON1 = %11101111

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BRGH 0
    DEFINE HSER_SPBRG 64
    DEFINE HSER_CLOERR 1

    GoTo STARTUP

    STARTUP:
    LCDOut $FE,1,"Data Logger V1.0"
    LCDOut $FE,$C0,"Reseting "
    PortB.0 = 1
    PortB.1 = 1
    PortB.2 = 1
    Pause 100
    PORTB.0=0 : PORTB.1=0 : PORTB.2=0 : PORTB.3=0 : PORTB.4=0 : PORTB.7=1
    PORTC.0=0
    PORTF.5=0 : PORTF.7=0
    GOTO MAIN

    MAIN: LCDOut $FE,1,"Press button "
    LCDOut $FE,$C0,"to start logging"
    PAUSE 100
    'IF PORTC.2 = 0 Then START
    Goto start 'MAIN

    START: SOUND PORTB.7,[127,5]
    GOTO Sens1

    SENS1: ADCON0 = %00010001
    ADCON1 = %11101010
    ADCIN 1, B2 'Read Value of RTC
    B3 = B2 >> 2
    ADCON1 = %11101110
    ADCON0.0=0
    PAUSE 100
    LCDOut $FE,1,"Sensor 1 = ",#B3
    PortB.0 = 1
    PAUSE 50
    Portb.0 = 0
    B3 = 123 'Set B3 to known value for testing Port
    HSEROUT [DEC B3,13,10]
    PAUSE 100
    GOTO SENS1

    END

    Here is an example of what comes out (using Serial Communicator)

    0> 00~0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>p~ 00>0> 00>0> p0>0> 00>0> 00~0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>p~ 00>0> 00>0> p0>0> 00>0> 00~0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>p~ 00>0> 00>0> p0>0> 00>0> 00~0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>0> 00>p~ 00>0

    Would somebody please help me, I've done all the usual "try everything/anything" " late nights" "
    Regards Mark Scotford
    [email protected] (remove the X to reply)

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BRGH 0   <-- Don't exist
    DEFINE HSER_SPBRG 64
    DEFINE HSER_CLOERR 1  <-- HSER_CLROERR
    @12MHZ what is the expected baudrate? 2400?
    using the calc i done few month ago
    @12 MHZ you must use the following
    Code:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 77 ' 2400 Bauds
    DEFINE HSER_CLROERR 1
    about now?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Steve, you beat me to it, I was just downloading your Calculator program (thank you for sharing your work with us).

    I posted in the new values Unfortunaly there is still garbage coming up in Serial Communicator (see example below) although it does seem more consistent.

    p~p~p~p~p~ p~p~p~p~p~ p~p~p~p~p~ p~p~p~p~p~

  4. #4
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    When you see that kind of data,you will be sure that the baudrate is not propper together with the parity and the number of data and stopbits.
    Try to figger out what is the right baudrate. You can play with your settings of your read program

  5. #5
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Slight correction to the wording of my original post. It should have read 12Mhz Crystal clock and not 10, although I did have it right in my coding as far as the DEFINE OSC 12 was correct. I could not work out why my calculations were wrong when compared to the results from Steve's excellent calculator (link shown below). A stupid mistake, but after correcting things, it still does not make any difference to the problem I am having. I have tried changing all the Parameters in Serial Communicator to all the different combinations of settings available and still no joy.

    http://www.picbasic.co.uk/forum/atta...tachmentid=316

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Or the config fuses are not set correctly, or the OSC speed is not the right one OR the MAX232 circuit is bad OR there's a little hardware problem, OR the serial communicator is not set properly OR all DEFINEs are not written in UPPERCASE.

    Bellow is tested and work on a 16f877.. but it shouldn't make any difference whatever PIC you're using...
    Code:
    define OSC 12
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 77 ' 2400 Bauds
    DEFINE HSER_CLROERR 1
    
    START:
        hSEROUT ["HELLO, THIS IS A TEST",13,10]
        PAUSE 100
        GOTO START
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=959&stc=1&d=1152544022 ">
    Attached Images Attached Images  
    Last edited by mister_e; - 10th July 2006 at 16:07.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    mmm... what about if ...
    Code:
    define OSC 12
    RCSTA1=$90
    TXSTA1=$20
    SPBRG1= 77 ' 2400 Bauds
    DEFINE HSER_CLROERR 1
    
    START:
        hSEROUT ["HELLO, THIS IS A TEST",13,10]
        PAUSE 100
        GOTO START
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Steve, I get this out, and I have my Serial Communicator set up the same as the prevous posters

    ppp ppp ppp ppp pppp ppp pp

  9. #9
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Is your powersupply oscillating?
    Did you mount a capacitor over the supply points of the chips?

  10. #10
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Yep, all chips have a 104 Cap near-by. Hold fire a while on this problem chaps. I tried programming an EPROM version of the processor instead of using my beloved ICEPIC2, and I am getting nothing happening, unfortunetly I have to go out now, but will continue tomorrow.

  11. #11
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Appologies are due, especially to Steve and Matt. I made the fundamental mistake of believing what I was being told, a colleague said he had given me a known working board. The problem was the Loading Caps on the Oscillator crystal were of the wrong value (too high a value) which were not enough to completely cripple my ICEPIC2 but were enough to affect the speed.

    I am now getting comms. and I did that thing of jumping up and down when the word "hello" appeared in Serial Communicator.

    Thanks to everybody who helped and sorry if I wasted your time.

  12. #12
    Mark Scotford's Avatar
    Mark Scotford Guest


    Did you find this post helpful? Yes | No

    Default

    Just as a side issue, I plugged my ICEPIC2 back in, and I got garbage out again, on checking I find that ICEPIC2 uses its own clock of 4Mhz, (in my defence I got this secondhand so I do not have the manual) 4Mhz is the frequency I normally use on my PIC projects, so it has not been an issue before. Anyway just changed the crystal to 4Mhz, changed the settings in my code, run ICEPIC2 again and everything is working fine, so I am off and running, thanks to all.

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    may happen dude. Nice to know you find the problem and learned from it.

    Have fun!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. I2C Slave with a PIC
    By ralfmayr in forum mel PIC BASIC Pro
    Replies: 129
    Last Post: - 21st August 2016, 17:44
  2. hserin and sms controller
    By xxxxxx in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 10th February 2010, 15:49
  3. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  4. Is HSEROUT corrupting bit 7 ?????
    By Robert Wells in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd October 2008, 16:26
  5. Controlling an 240x128 LCD Touchpanel Display
    By Vincent in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 7th June 2006, 23:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts