Serial data sent to 16F627A being read incorrectly by PIC?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2005
    Posts
    53

    Default Serial data sent to 16F627A being read incorrectly by PIC?

    I'm having a problem with trying to read a single byte over hardware serial @ 2400 8N1 on a 16F627A running at 4Mhz. I've created a very thin program below to simply read the byte on the hardware RX (B1) and send it back out on the hardware TX (B2) but what it echoes out is not what is sent to it (I verified what is being sent with a logic analyzer)

    Code:
    include "modedefs.bas"
    #CONFIG
        __config _FOSC_INTOSCIO & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
    #ENDCONFIG
    define OSC 4
    define HSER_CLROERR 1
    define HSER_RCSTA 90h
    define HSER_TXSTA 24h
    define HSER_BAUD 2400
    
    Loop:
        if PIR1.5 then hserout [RCREG]
    goto Loop
    I originally had some variables naming the PIR1.5, etc. and a variable to store the byte that was read in but moved to this when testing (and both ways act the same)

    Essentially if I send a byte, the PIC reads it in "wrong". I've verified the data coming into the PIC and going back out with logic analyzer and the issue seems limited to the RX side. I just made a PC program to send a single byte from an FTDI USB/serial adapter from 0x00 to 0xFF and record what the PIC sees and responds:
    Code:
    Sent to PIC: 0 dec (0x00 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 1 dec (0x01 hex), what PIC sees is 127 dec (0x7f hex)
    Sent to PIC: 2 dec (0x02 hex), what PIC sees is 63 dec (0x3f hex)
    Sent to PIC: 3 dec (0x03 hex), what PIC sees is 126 dec (0x7e hex)
    Sent to PIC: 4 dec (0x04 hex), what PIC sees is 31 dec (0x1f hex)
    Sent to PIC: 5 dec (0x05 hex), what PIC sees is 125 dec (0x7d hex)
    Sent to PIC: 6 dec (0x06 hex), what PIC sees is 62 dec (0x3e hex)
    Sent to PIC: 7 dec (0x07 hex), what PIC sees is 124 dec (0x7c hex)
    Sent to PIC: 8 dec (0x08 hex), what PIC sees is 15 dec (0x0f hex)
    Sent to PIC: 9 dec (0x09 hex), what PIC sees is 123 dec (0x7b hex)
    Sent to PIC: 10 dec (0x0a hex), what PIC sees is 61 dec (0x3d hex)
    Sent to PIC: 11 dec (0x0b hex), what PIC sees is 122 dec (0x7a hex)
    Sent to PIC: 12 dec (0x0c hex), what PIC sees is 30 dec (0x1e hex)
    Sent to PIC: 13 dec (0x0d hex), what PIC sees is 121 dec (0x79 hex)
    Sent to PIC: 14 dec (0x0e hex), what PIC sees is 60 dec (0x3c hex)
    Sent to PIC: 15 dec (0x0f hex), what PIC sees is 120 dec (0x78 hex)
    Sent to PIC: 16 dec (0x10 hex), what PIC sees is 7 dec (0x07 hex)
    Sent to PIC: 17 dec (0x11 hex), what PIC sees is 119 dec (0x77 hex)
    Sent to PIC: 18 dec (0x12 hex), what PIC sees is 59 dec (0x3b hex)
    Sent to PIC: 19 dec (0x13 hex), what PIC sees is 118 dec (0x76 hex)
    Sent to PIC: 20 dec (0x14 hex), what PIC sees is 29 dec (0x1d hex)
    Sent to PIC: 21 dec (0x15 hex), what PIC sees is 117 dec (0x75 hex)
    Sent to PIC: 22 dec (0x16 hex), what PIC sees is 58 dec (0x3a hex)
    Sent to PIC: 23 dec (0x17 hex), what PIC sees is 116 dec (0x74 hex)
    Sent to PIC: 24 dec (0x18 hex), what PIC sees is 14 dec (0x0e hex)
    Sent to PIC: 25 dec (0x19 hex), what PIC sees is 115 dec (0x73 hex)
    Sent to PIC: 26 dec (0x1a hex), what PIC sees is 57 dec (0x39 hex)
    Sent to PIC: 27 dec (0x1b hex), what PIC sees is 114 dec (0x72 hex)
    Sent to PIC: 28 dec (0x1c hex), what PIC sees is 28 dec (0x1c hex)
    Sent to PIC: 29 dec (0x1d hex), what PIC sees is 113 dec (0x71 hex)
    Sent to PIC: 30 dec (0x1e hex), what PIC sees is 56 dec (0x38 hex)
    Sent to PIC: 31 dec (0x1f hex), what PIC sees is 112 dec (0x70 hex)
    Sent to PIC: 32 dec (0x20 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 33 dec (0x21 hex), what PIC sees is 111 dec (0x6f hex)
    Sent to PIC: 34 dec (0x22 hex), what PIC sees is 55 dec (0x37 hex)
    Sent to PIC: 35 dec (0x23 hex), what PIC sees is 110 dec (0x6e hex)
    Sent to PIC: 36 dec (0x24 hex), what PIC sees is 27 dec (0x1b hex)
    Sent to PIC: 37 dec (0x25 hex), what PIC sees is 109 dec (0x6d hex)
    Sent to PIC: 38 dec (0x26 hex), what PIC sees is 54 dec (0x36 hex)
    Sent to PIC: 39 dec (0x27 hex), what PIC sees is 108 dec (0x6c hex)
    Sent to PIC: 40 dec (0x28 hex), what PIC sees is 13 dec (0x0d hex)
    Sent to PIC: 41 dec (0x29 hex), what PIC sees is 107 dec (0x6b hex)
    Sent to PIC: 42 dec (0x2a hex), what PIC sees is 53 dec (0x35 hex)
    Sent to PIC: 43 dec (0x2b hex), what PIC sees is 106 dec (0x6a hex)
    Sent to PIC: 44 dec (0x2c hex), what PIC sees is 26 dec (0x1a hex)
    Sent to PIC: 45 dec (0x2d hex), what PIC sees is 105 dec (0x69 hex)
    Sent to PIC: 46 dec (0x2e hex), what PIC sees is 52 dec (0x34 hex)
    Sent to PIC: 47 dec (0x2f hex), what PIC sees is 104 dec (0x68 hex)
    Sent to PIC: 48 dec (0x30 hex), what PIC sees is 6 dec (0x06 hex)
    Sent to PIC: 49 dec (0x31 hex), what PIC sees is 103 dec (0x67 hex)
    Sent to PIC: 50 dec (0x32 hex), what PIC sees is 51 dec (0x33 hex)
    Sent to PIC: 51 dec (0x33 hex), what PIC sees is 102 dec (0x66 hex)
    Sent to PIC: 52 dec (0x34 hex), what PIC sees is 25 dec (0x19 hex)
    Sent to PIC: 53 dec (0x35 hex), what PIC sees is 101 dec (0x65 hex)
    Sent to PIC: 54 dec (0x36 hex), what PIC sees is 50 dec (0x32 hex)
    Sent to PIC: 55 dec (0x37 hex), what PIC sees is 100 dec (0x64 hex)
    Sent to PIC: 56 dec (0x38 hex), what PIC sees is 12 dec (0x0c hex)
    Sent to PIC: 57 dec (0x39 hex), what PIC sees is 99 dec (0x63 hex)
    Sent to PIC: 58 dec (0x3a hex), what PIC sees is 49 dec (0x31 hex)
    Sent to PIC: 59 dec (0x3b hex), what PIC sees is 98 dec (0x62 hex)
    Sent to PIC: 60 dec (0x3c hex), what PIC sees is 24 dec (0x18 hex)
    Sent to PIC: 61 dec (0x3d hex), what PIC sees is 97 dec (0x61 hex)
    Sent to PIC: 62 dec (0x3e hex), what PIC sees is 48 dec (0x30 hex)
    Sent to PIC: 63 dec (0x3f hex), what PIC sees is 96 dec (0x60 hex)
    Sent to PIC: 64 dec (0x40 hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 65 dec (0x41 hex), what PIC sees is 95 dec (0x5f hex)
    Sent to PIC: 66 dec (0x42 hex), what PIC sees is 47 dec (0x2f hex)
    Sent to PIC: 67 dec (0x43 hex), what PIC sees is 94 dec (0x5e hex)
    Sent to PIC: 68 dec (0x44 hex), what PIC sees is 23 dec (0x17 hex)
    Sent to PIC: 69 dec (0x45 hex), what PIC sees is 93 dec (0x5d hex)
    Sent to PIC: 70 dec (0x46 hex), what PIC sees is 46 dec (0x2e hex)
    Sent to PIC: 71 dec (0x47 hex), what PIC sees is 92 dec (0x5c hex)
    Sent to PIC: 72 dec (0x48 hex), what PIC sees is 11 dec (0x0b hex)
    Sent to PIC: 73 dec (0x49 hex), what PIC sees is 91 dec (0x5b hex)
    Sent to PIC: 74 dec (0x4a hex), what PIC sees is 45 dec (0x2d hex)
    Sent to PIC: 75 dec (0x4b hex), what PIC sees is 90 dec (0x5a hex)
    Sent to PIC: 76 dec (0x4c hex), what PIC sees is 22 dec (0x16 hex)
    Sent to PIC: 77 dec (0x4d hex), what PIC sees is 89 dec (0x59 hex)
    Sent to PIC: 78 dec (0x4e hex), what PIC sees is 44 dec (0x2c hex)
    Sent to PIC: 79 dec (0x4f hex), what PIC sees is 88 dec (0x58 hex)
    Sent to PIC: 80 dec (0x50 hex), what PIC sees is 5 dec (0x05 hex)
    Sent to PIC: 81 dec (0x51 hex), what PIC sees is 87 dec (0x57 hex)
    Sent to PIC: 82 dec (0x52 hex), what PIC sees is 43 dec (0x2b hex)
    Sent to PIC: 83 dec (0x53 hex), what PIC sees is 86 dec (0x56 hex)
    Sent to PIC: 84 dec (0x54 hex), what PIC sees is 21 dec (0x15 hex)
    Sent to PIC: 85 dec (0x55 hex), what PIC sees is 85 dec (0x55 hex)
    Sent to PIC: 86 dec (0x56 hex), what PIC sees is 42 dec (0x2a hex)
    Sent to PIC: 87 dec (0x57 hex), what PIC sees is 84 dec (0x54 hex)
    Sent to PIC: 88 dec (0x58 hex), what PIC sees is 10 dec (0x0a hex)
    Sent to PIC: 89 dec (0x59 hex), what PIC sees is 83 dec (0x53 hex)
    Sent to PIC: 90 dec (0x5a hex), what PIC sees is 41 dec (0x29 hex)
    Sent to PIC: 91 dec (0x5b hex), what PIC sees is 82 dec (0x52 hex)
    Sent to PIC: 92 dec (0x5c hex), what PIC sees is 20 dec (0x14 hex)
    Sent to PIC: 93 dec (0x5d hex), what PIC sees is 81 dec (0x51 hex)
    Sent to PIC: 94 dec (0x5e hex), what PIC sees is 40 dec (0x28 hex)
    Sent to PIC: 95 dec (0x5f hex), what PIC sees is 80 dec (0x50 hex)
    Sent to PIC: 96 dec (0x60 hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 97 dec (0x61 hex), what PIC sees is 79 dec (0x4f hex)
    Sent to PIC: 98 dec (0x62 hex), what PIC sees is 39 dec (0x27 hex)
    Sent to PIC: 99 dec (0x63 hex), what PIC sees is 78 dec (0x4e hex)
    Sent to PIC: 100 dec (0x64 hex), what PIC sees is 19 dec (0x13 hex)
    Sent to PIC: 101 dec (0x65 hex), what PIC sees is 77 dec (0x4d hex)
    Sent to PIC: 102 dec (0x66 hex), what PIC sees is 38 dec (0x26 hex)
    Sent to PIC: 103 dec (0x67 hex), what PIC sees is 76 dec (0x4c hex)
    Sent to PIC: 104 dec (0x68 hex), what PIC sees is 9 dec (0x09 hex)
    Sent to PIC: 105 dec (0x69 hex), what PIC sees is 75 dec (0x4b hex)
    Sent to PIC: 106 dec (0x6a hex), what PIC sees is 37 dec (0x25 hex)
    Sent to PIC: 107 dec (0x6b hex), what PIC sees is 74 dec (0x4a hex)
    Sent to PIC: 108 dec (0x6c hex), what PIC sees is 18 dec (0x12 hex)
    Sent to PIC: 109 dec (0x6d hex), what PIC sees is 73 dec (0x49 hex)
    Sent to PIC: 110 dec (0x6e hex), what PIC sees is 36 dec (0x24 hex)
    Sent to PIC: 111 dec (0x6f hex), what PIC sees is 72 dec (0x48 hex)
    Sent to PIC: 112 dec (0x70 hex), what PIC sees is 4 dec (0x04 hex)
    Sent to PIC: 113 dec (0x71 hex), what PIC sees is 71 dec (0x47 hex)
    Sent to PIC: 114 dec (0x72 hex), what PIC sees is 35 dec (0x23 hex)
    Sent to PIC: 115 dec (0x73 hex), what PIC sees is 70 dec (0x46 hex)
    Sent to PIC: 116 dec (0x74 hex), what PIC sees is 17 dec (0x11 hex)
    Sent to PIC: 117 dec (0x75 hex), what PIC sees is 69 dec (0x45 hex)
    Sent to PIC: 118 dec (0x76 hex), what PIC sees is 34 dec (0x22 hex)
    Sent to PIC: 119 dec (0x77 hex), what PIC sees is 68 dec (0x44 hex)
    Sent to PIC: 120 dec (0x78 hex), what PIC sees is 8 dec (0x08 hex)
    Sent to PIC: 121 dec (0x79 hex), what PIC sees is 67 dec (0x43 hex)
    Sent to PIC: 122 dec (0x7a hex), what PIC sees is 33 dec (0x21 hex)
    Sent to PIC: 123 dec (0x7b hex), what PIC sees is 66 dec (0x42 hex)
    Sent to PIC: 124 dec (0x7c hex), what PIC sees is 16 dec (0x10 hex)
    Sent to PIC: 125 dec (0x7d hex), what PIC sees is 65 dec (0x41 hex)
    Sent to PIC: 126 dec (0x7e hex), what PIC sees is 32 dec (0x20 hex)
    Sent to PIC: 127 dec (0x7f hex), what PIC sees is 64 dec (0x40 hex)
    Sent to PIC: 128 dec (0x80 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 129 dec (0x81 hex), what PIC sees is 63 dec (0x3f hex)
    Sent to PIC: 130 dec (0x82 hex), what PIC sees is 31 dec (0x1f hex)
    Sent to PIC: 131 dec (0x83 hex), what PIC sees is 62 dec (0x3e hex)
    Sent to PIC: 132 dec (0x84 hex), what PIC sees is 15 dec (0x0f hex)
    Sent to PIC: 133 dec (0x85 hex), what PIC sees is 61 dec (0x3d hex)
    Sent to PIC: 134 dec (0x86 hex), what PIC sees is 30 dec (0x1e hex)
    Sent to PIC: 135 dec (0x87 hex), what PIC sees is 60 dec (0x3c hex)
    Sent to PIC: 136 dec (0x88 hex), what PIC sees is 7 dec (0x07 hex)
    Sent to PIC: 137 dec (0x89 hex), what PIC sees is 59 dec (0x3b hex)
    Sent to PIC: 138 dec (0x8a hex), what PIC sees is 29 dec (0x1d hex)
    Sent to PIC: 139 dec (0x8b hex), what PIC sees is 58 dec (0x3a hex)
    Sent to PIC: 140 dec (0x8c hex), what PIC sees is 14 dec (0x0e hex)
    Sent to PIC: 141 dec (0x8d hex), what PIC sees is 57 dec (0x39 hex)
    Sent to PIC: 142 dec (0x8e hex), what PIC sees is 28 dec (0x1c hex)
    Sent to PIC: 143 dec (0x8f hex), what PIC sees is 56 dec (0x38 hex)
    Sent to PIC: 144 dec (0x90 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 145 dec (0x91 hex), what PIC sees is 55 dec (0x37 hex)
    Sent to PIC: 146 dec (0x92 hex), what PIC sees is 27 dec (0x1b hex)
    Sent to PIC: 147 dec (0x93 hex), what PIC sees is 54 dec (0x36 hex)
    Sent to PIC: 148 dec (0x94 hex), what PIC sees is 13 dec (0x0d hex)
    Sent to PIC: 149 dec (0x95 hex), what PIC sees is 53 dec (0x35 hex)
    Sent to PIC: 150 dec (0x96 hex), what PIC sees is 26 dec (0x1a hex)
    Sent to PIC: 151 dec (0x97 hex), what PIC sees is 52 dec (0x34 hex)
    Sent to PIC: 152 dec (0x98 hex), what PIC sees is 6 dec (0x06 hex)
    Sent to PIC: 153 dec (0x99 hex), what PIC sees is 51 dec (0x33 hex)
    Sent to PIC: 154 dec (0x9a hex), what PIC sees is 25 dec (0x19 hex)
    Sent to PIC: 155 dec (0x9b hex), what PIC sees is 50 dec (0x32 hex)
    Sent to PIC: 156 dec (0x9c hex), what PIC sees is 12 dec (0x0c hex)
    Sent to PIC: 157 dec (0x9d hex), what PIC sees is 49 dec (0x31 hex)
    Sent to PIC: 158 dec (0x9e hex), what PIC sees is 24 dec (0x18 hex)
    Sent to PIC: 159 dec (0x9f hex), what PIC sees is 48 dec (0x30 hex)
    Sent to PIC: 160 dec (0xa0 hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 161 dec (0xa1 hex), what PIC sees is 47 dec (0x2f hex)
    Sent to PIC: 162 dec (0xa2 hex), what PIC sees is 23 dec (0x17 hex)
    Sent to PIC: 163 dec (0xa3 hex), what PIC sees is 46 dec (0x2e hex)
    Sent to PIC: 164 dec (0xa4 hex), what PIC sees is 11 dec (0x0b hex)
    Sent to PIC: 165 dec (0xa5 hex), what PIC sees is 45 dec (0x2d hex)
    Sent to PIC: 166 dec (0xa6 hex), what PIC sees is 22 dec (0x16 hex)
    Sent to PIC: 167 dec (0xa7 hex), what PIC sees is 44 dec (0x2c hex)
    Sent to PIC: 168 dec (0xa8 hex), what PIC sees is 5 dec (0x05 hex)
    Sent to PIC: 169 dec (0xa9 hex), what PIC sees is 43 dec (0x2b hex)
    Sent to PIC: 170 dec (0xaa hex), what PIC sees is 21 dec (0x15 hex)
    Sent to PIC: 171 dec (0xab hex), what PIC sees is 42 dec (0x2a hex)
    Sent to PIC: 172 dec (0xac hex), what PIC sees is 10 dec (0x0a hex)
    Sent to PIC: 173 dec (0xad hex), what PIC sees is 41 dec (0x29 hex)
    Sent to PIC: 174 dec (0xae hex), what PIC sees is 20 dec (0x14 hex)
    Sent to PIC: 175 dec (0xaf hex), what PIC sees is 40 dec (0x28 hex)
    Sent to PIC: 176 dec (0xb0 hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 177 dec (0xb1 hex), what PIC sees is 39 dec (0x27 hex)
    Sent to PIC: 178 dec (0xb2 hex), what PIC sees is 19 dec (0x13 hex)
    Sent to PIC: 179 dec (0xb3 hex), what PIC sees is 38 dec (0x26 hex)
    Sent to PIC: 180 dec (0xb4 hex), what PIC sees is 9 dec (0x09 hex)
    Sent to PIC: 181 dec (0xb5 hex), what PIC sees is 37 dec (0x25 hex)
    Sent to PIC: 182 dec (0xb6 hex), what PIC sees is 18 dec (0x12 hex)
    Sent to PIC: 183 dec (0xb7 hex), what PIC sees is 36 dec (0x24 hex)
    Sent to PIC: 184 dec (0xb8 hex), what PIC sees is 4 dec (0x04 hex)
    Sent to PIC: 185 dec (0xb9 hex), what PIC sees is 35 dec (0x23 hex)
    Sent to PIC: 186 dec (0xba hex), what PIC sees is 17 dec (0x11 hex)
    Sent to PIC: 187 dec (0xbb hex), what PIC sees is 34 dec (0x22 hex)
    Sent to PIC: 188 dec (0xbc hex), what PIC sees is 8 dec (0x08 hex)
    Sent to PIC: 189 dec (0xbd hex), what PIC sees is 33 dec (0x21 hex)
    Sent to PIC: 190 dec (0xbe hex), what PIC sees is 16 dec (0x10 hex)
    Sent to PIC: 191 dec (0xbf hex), what PIC sees is 32 dec (0x20 hex)
    Sent to PIC: 192 dec (0xc0 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 193 dec (0xc1 hex), what PIC sees is 31 dec (0x1f hex)
    Sent to PIC: 194 dec (0xc2 hex), what PIC sees is 15 dec (0x0f hex)
    Sent to PIC: 195 dec (0xc3 hex), what PIC sees is 30 dec (0x1e hex)
    Sent to PIC: 196 dec (0xc4 hex), what PIC sees is 7 dec (0x07 hex)
    Sent to PIC: 197 dec (0xc5 hex), what PIC sees is 29 dec (0x1d hex)
    Sent to PIC: 198 dec (0xc6 hex), what PIC sees is 14 dec (0x0e hex)
    Sent to PIC: 199 dec (0xc7 hex), what PIC sees is 28 dec (0x1c hex)
    Sent to PIC: 200 dec (0xc8 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 201 dec (0xc9 hex), what PIC sees is 27 dec (0x1b hex)
    Sent to PIC: 202 dec (0xca hex), what PIC sees is 13 dec (0x0d hex)
    Sent to PIC: 203 dec (0xcb hex), what PIC sees is 26 dec (0x1a hex)
    Sent to PIC: 204 dec (0xcc hex), what PIC sees is 6 dec (0x06 hex)
    Sent to PIC: 205 dec (0xcd hex), what PIC sees is 25 dec (0x19 hex)
    Sent to PIC: 206 dec (0xce hex), what PIC sees is 12 dec (0x0c hex)
    Sent to PIC: 207 dec (0xcf hex), what PIC sees is 24 dec (0x18 hex)
    Sent to PIC: 208 dec (0xd0 hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 209 dec (0xd1 hex), what PIC sees is 23 dec (0x17 hex)
    Sent to PIC: 210 dec (0xd2 hex), what PIC sees is 11 dec (0x0b hex)
    Sent to PIC: 211 dec (0xd3 hex), what PIC sees is 22 dec (0x16 hex)
    Sent to PIC: 212 dec (0xd4 hex), what PIC sees is 5 dec (0x05 hex)
    Sent to PIC: 213 dec (0xd5 hex), what PIC sees is 21 dec (0x15 hex)
    Sent to PIC: 214 dec (0xd6 hex), what PIC sees is 10 dec (0x0a hex)
    Sent to PIC: 215 dec (0xd7 hex), what PIC sees is 20 dec (0x14 hex)
    Sent to PIC: 216 dec (0xd8 hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 217 dec (0xd9 hex), what PIC sees is 19 dec (0x13 hex)
    Sent to PIC: 218 dec (0xda hex), what PIC sees is 9 dec (0x09 hex)
    Sent to PIC: 219 dec (0xdb hex), what PIC sees is 18 dec (0x12 hex)
    Sent to PIC: 220 dec (0xdc hex), what PIC sees is 4 dec (0x04 hex)
    Sent to PIC: 221 dec (0xdd hex), what PIC sees is 17 dec (0x11 hex)
    Sent to PIC: 222 dec (0xde hex), what PIC sees is 8 dec (0x08 hex)
    Sent to PIC: 223 dec (0xdf hex), what PIC sees is 16 dec (0x10 hex)
    Sent to PIC: 224 dec (0xe0 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 225 dec (0xe1 hex), what PIC sees is 15 dec (0x0f hex)
    Sent to PIC: 226 dec (0xe2 hex), what PIC sees is 7 dec (0x07 hex)
    Sent to PIC: 227 dec (0xe3 hex), what PIC sees is 14 dec (0x0e hex)
    Sent to PIC: 228 dec (0xe4 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 229 dec (0xe5 hex), what PIC sees is 13 dec (0x0d hex)
    Sent to PIC: 230 dec (0xe6 hex), what PIC sees is 6 dec (0x06 hex)
    Sent to PIC: 231 dec (0xe7 hex), what PIC sees is 12 dec (0x0c hex)
    Sent to PIC: 232 dec (0xe8 hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 233 dec (0xe9 hex), what PIC sees is 11 dec (0x0b hex)
    Sent to PIC: 234 dec (0xea hex), what PIC sees is 5 dec (0x05 hex)
    Sent to PIC: 235 dec (0xeb hex), what PIC sees is 10 dec (0x0a hex)
    Sent to PIC: 236 dec (0xec hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 237 dec (0xed hex), what PIC sees is 9 dec (0x09 hex)
    Sent to PIC: 238 dec (0xee hex), what PIC sees is 4 dec (0x04 hex)
    Sent to PIC: 239 dec (0xef hex), what PIC sees is 8 dec (0x08 hex)
    Sent to PIC: 240 dec (0xf0 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 241 dec (0xf1 hex), what PIC sees is 7 dec (0x07 hex)
    Sent to PIC: 242 dec (0xf2 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 243 dec (0xf3 hex), what PIC sees is 6 dec (0x06 hex)
    Sent to PIC: 244 dec (0xf4 hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 245 dec (0xf5 hex), what PIC sees is 5 dec (0x05 hex)
    Sent to PIC: 246 dec (0xf6 hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 247 dec (0xf7 hex), what PIC sees is 4 dec (0x04 hex)
    Sent to PIC: 248 dec (0xf8 hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 249 dec (0xf9 hex), what PIC sees is 3 dec (0x03 hex)
    Sent to PIC: 250 dec (0xfa hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 251 dec (0xfb hex), what PIC sees is 2 dec (0x02 hex)
    Sent to PIC: 252 dec (0xfc hex), what PIC sees is 0 dec (0x00 hex)
    Sent to PIC: 253 dec (0xfd hex), what PIC sees is 1 dec (0x01 hex)
    Sent to PIC: 254 dec (0xfe hex), what PIC sees is 0 dec (0x00 hex)
    There is a bit of a pattern in there where the odd numbers count down from 127 (e.g. 1 is seen as 127, 3 is seen as 126, 251 is seen as 2, 253 is seen as 1) and the even numbers count down from the lower bits (every 2nd even number counts down from 63, every 4th even counts down from 31, every 8th counts down from 15 every 16th counts down from 7, etc.)

    Any idea why this might be happening? The TX side seems perfectly fine but the RX always sees the bytes on the right when it receives the byte on the left.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    If you connect PIC directly or via resistors to PC, 7 bits are sent only.

    Add Max232 or MAX3232 type of RS232 chip in between the PIC and the PC.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    Take the PC out of the loop you're just introducing more variables, your LA is all you need.

    A couple of things to check, is the Fosc (the clock running the PIC, not necesarily the crystal) you tell the compiler is the same as the actual? Is the signal inverted?

    Use your LA to decode the signals and look at the polarity? Let the LA determine the baud rate or calculate the bit time at 2400 and measure it on the LA.
    George

  4. #4
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    I should have elaborated more on the PC part; I moved to sending bytes via PC as a direct result of this issue. The PIC in question is actually supposed to be talking to another device via serial - I need to send a byte to this device to query it and then it responds with a few bytes I need to capture. I can successfully send the byte to the device and the PIC captures the correct amount of bytes in return but it just captures the "wrong" bytes. I changed my code on the PIC to look for these "wrong" bytes and it actually functions but this is quite a hack and I'd like to sort out why it's not reading them properly in the first place.

    I put together the simple code above and connected to the FTDI on my computer to be able to quickly test the result of sending various bytes to the PIC to see their result. The bytes my PC send are interpreted by the PIC the same as the bytes the other device was sending (e.g. device/PC sends 0x0A [confirmed w/ LA] but PIC sees 0x3D)

    The RX signal is not inverted. The device is listening for an inverted signal to start but that's on the TX side which is passed through an inverter. The TX from the PIC is successfully received by the device and the device's response (not inverted) does not function.

    Confirming the baud with the logic analyzer is a good idea; I'll have to do that and report the value. I believe I did have it set to "autobaud" when I first tested and it was something like 2389 or slightly off from 2400 baud but I will confirm again to be sure.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    just tried your code on a 16f648a , works perfectly from my pc usb through tty converter to pic , you must have polarity of signal screwed up.
    Attached Images Attached Images  
    Warning I'm not a teacher

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    The difference between 2389 and 2400 would not seem a big deal, it only 0.5% (if my maths right, which is unlikely)
    George

  7. #7
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: Serial data sent to 16F627A being read incorrectly by PIC?

    I traced out the board and realized another component sitting between the board input and PIC was inverting the signal. The board is being re-purposed from a different use so I was able to bypass that and everything is working as expected. Thanks

Similar Threads

  1. how to buffer serial data on pic?
    By kiteman in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th March 2010, 20:07
  2. How to read PIC serial no. from EEPROM with PBP?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th December 2009, 11:27
  3. Forward Serial Data from pic to pc
    By Muller in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd September 2008, 22:46
  4. How to read Serial number programmed into PIC
    By freddayz in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd April 2008, 03:36
  5. PIC to PIC Serial data using Cat5 cable
    By Andy Wood in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd May 2007, 03:42

Members who have read this thread : 1

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