Hi Filip, Good to see that it is solved but there is one thing I do not understand. You mentioned that the baudrate on the PC and the PIC are different in order to work.
Then I see this code: pragma target clock 20_000_000 -- oscillator frequency pragma target OSC OFF -- HS crystal or resonator pragma target RSTOSC HFINT32 -- power-up clock select: OSC So you define a target clock of 20 MHz (which the compiler uses for timing) but you select an internal clock of 32 MHz (which the PIC uses for timing). This mismatch will result in a mismatch of the baudrate too since serial software 'assumes' a 20 MHz clock but in fact the PIC is running on 32 MHz. Can you set the target clock to 32_000_00 and the baudrate on the PIC the same as the PC to see if that solves that problem? Thanks Kind regards, Rob ________________________________ Van: [email protected] <[email protected]> namens flyway38 <[email protected]> Verzonden: woensdag 18 mei 2022 16:25 Aan: jallib <[email protected]> Onderwerp: Re: [jallib] Help about serial_hardware library for the 16F18313 Hi all, You guys are awesome. This case is closed. That was it. I had inverted both TX and RX in my FTDI cabe configuration. BUT, only TX should be inverted. Thank you VERY much guys. This community is great. PS: @Matt, Am using internal oscillator and no free pins on my PIC. Cheers to you all!! Best regrads, Filipe Santos. On Wednesday, May 18, 2022 at 6:45:05 AM UTC+1 Kiste wrote: Great, that error is fixed :-) Now here's what the PIC sends, and what I presume the PC receives: Seq. Lvl Pic sends PC receives (inverted) -3 1 idle framing error -2 1 idle framing error -1 1 idle framing error 0 0 startbit idle 1 0 0*1+ idle 2 1 1*2+ startbit 3 0 0*4+ 1*1+ 4 0 0*8=2 1*2+ 5 0 0*1+ 1*4+ 6 1 1*2+ 0*8=7 7 0 0*4+ 1*1+ 8 0 0*8=2 2*2+ 9 1 Stopbit 0*4+ 10 0 startbit 1*8=b 11 0 0*1+ stopbit 12 1 1*2+ startbit 13 0 0*4+ 1*1+ 14 0 0*8=2 1*2+ 15 0 0*1+ 1*4+ 16 1 1*2+ 0*8=7 17 0 0*4+ 1*1+ 18 0 0*8=2 1*2+ 19 1 Stopbit 0*4+ 20 1 idle 0*8=3 21 1 idle framing error 22 1 idle framing error 23 1 idle framing error 24 1 idle framing error You see, "b7 37" is exactly what to expect when the baudrate is correct, and the polarity is not. You just need to fix the polarity. For the transmission from the PIC to the PC you can either switch RX on the PC to non-inverted mode, or invert TX on the PIC like BAUDCON1_SCKP=1 However, this PIC does not allow inverting its RX easily, so you need to switch the PCs TX to non-inverted mode or invert the signal by other means. That other means can be a transistor and two resistors, or a dedicated IC, even a NE555 can do it. Or, as mentioned before, if you've got an unused pin on the PIC, you can use an unused peripheral of your PIC to invert the signal. Greets, Kiste Am Dienstag, 17. Mai 2022, 23:16:31 MESZ hat flyway38 <[email protected]> Folgendes geschrieben: Hi Kiste, Thank you very much. That solved the baudrate issue. But serial_hardware still don't work as it should. Still have Frame and Break error on PC side. Now, your code; forever loop serial_hw_data=0x22 serial_hw_data=0x22 delay_1s(1) end loop Results; b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. b7 37 00 ·7. Cannot understand what's going on. Anymore ideas? Cheers, Filipe Santos. On Tuesday, May 17, 2022 at 8:34:17 PM UTC+1 Kiste wrote: So, here it is: pragma target clock 20_000_000 -- oscillator frequency pragma target RSTOSC HFINT32 -- power-up clock select: OSC You're telling the compiler, the PIC would run at 20MHz, and you're setting the PIC to 32MHz. Make it pragma target clock 32_000_000 -- oscillator frequency and your baudrate will be as specified. Greets, Kiste Am Dienstag, 17. Mai 2022, 21:12:10 MESZ hat flyway38 <[email protected]> Folgendes geschrieben: Hi again Kiste, Here my code pragmas; -- Pragmas/ configuration memory settings (fuses) pragma target clock 20_000_000 -- oscillator frequency pragma target OSC OFF -- HS crystal or resonator pragma target RSTOSC HFINT32 -- power-up clock select: OSC pragma target CLKOUTEN DISABLED -- no clock output pragma target WDT DISABLED -- watchdog pragma target DEBUG DISABLED -- no debugging pragma target BROWNOUT DISABLED -- no brownout reset pragma target FCMEN DISABLED -- no clock monitoring pragma target CSWEN ENABLED -- allow writing OSCCON1 NOSC and NDIV pragma target LVP DISABLED -- no low voltage programming pragma target MCLR EXTERNAL -- external reset -- The configuration bit settings above are only a selection, sufficient -- for this program. Other programs may need more or different settings. -- WDTCON_SWDTEN = OFF -- disable watchdog -- _usec_delay (100_000) -- wait for power to stablilize -- enable_digital_io() -- make all pins digital I/O Cheers Filipe Santos. On Tuesday, May 17, 2022 at 7:05:54 PM UTC+1 Kiste wrote: Hi Filipe, I suspect the baudrate problem in settings like pragma target clock ? pragma target OSC ? pragma target RSTOSC ? OSCCON* = ? What are these settings? Greets, Kiste -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/6e0906ee-c9ec-4f45-94fb-3f99356d83aen%40googlegroups.com<https://groups.google.com/d/msgid/jallib/6e0906ee-c9ec-4f45-94fb-3f99356d83aen%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/2a51961c-ca87-4ba0-b033-c7898ef83840n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/2a51961c-ca87-4ba0-b033-c7898ef83840n%40googlegroups.com?utm_medium=email&utm_source=footer> . -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/3f53b348-3d81-4035-9110-560b81045bfdn%40googlegroups.com<https://groups.google.com/d/msgid/jallib/3f53b348-3d81-4035-9110-560b81045bfdn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB1637BD0D5A5E1ADDB3FB113FE6D19%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM.
