View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9377 Location: Greensville,Ontario
|
|
Posted: Sun Jun 26, 2022 10:45 am |
|
|
putc(100) should show up on the PC terminal as 'd' |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 26, 2022 3:24 pm |
|
|
nailuy, can you tell us your CCS compiler version ? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 507 Location: Montenegro
|
|
Posted: Sun Jun 26, 2022 4:55 pm |
|
|
I played with the idea that those getenv's are not getting the right register address for APFCON0 and APFCON1 or to be more precise, getting the wrong bank. That would mean clearing bits in wrong registers and maybe setting both RX and TX on the same pin. I copied your code and got this in .lst file for clearing two bits with 5.078:
Code: |
0061: MOVLB 02
0062: CLRF 12
0063: CLRF 11
0064: CLRF 14
0065: CLRF 13
.................... {
....................
.................... BIT_clear(RXDTSEL,0); //RX to RB1
0066: BCF 1D.7
.................... BIT_clear(TXCKSEL,0); //TX to RB2
0067: BCF 1E.0
....................
....................
|
It selects the correct bank (bank2) and correct addresses. Do check your .lst what is happening. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9377 Location: Greensville,Ontario
|
|
Posted: Sun Jun 26, 2022 5:47 pm |
|
|
Curious, I looked at the device header... and there is a 'setup_uart() 'function to turn is on or off.
it could be that the default has the UART off, so maybe add
setup_uart(on); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 26, 2022 6:42 pm |
|
|
temtronic, so far you have told nailuy to
1. Not use a split program.
Well, the split program comes from the CCS IDE. That's how the IDE
does it. Because of this, you see it on the forum all the time.
2. Use setup_uart(on).
The #use rs232() statement causes the compiler to put startup code at
the beginning of main() that turns on the uart. It has always done this.
It's not necessary to call setup_uart() to do it again. This is in the LST file.
3. Disable comparators.
CCS automatically does this in the startup code. You don't need to do it
again. This can be seen in the .LST file. Also, the H/W default is to
disable them. You can see this in the 16F1826 data sheet:
REGISTER 19-1: CMxCON0: COMPARATOR Cx CONTROL REGISTER 0
For the CxON it (bit 7) it says: R/W-0/0
The 0/0 means that the bit is set to a 0 at Power-on and brownout reset,
and also in WDT reset. A 0 means "disabled". So the comparators are
disabled on power-up.
4. You told him to check APFCON. He does not need to do this. The
default power-on-reset setting for APFCON bit for Tx and Rx is all 0's.
This sets the PIC to use pins B2 and B1 for the Tx and Rx. This fits his
#use rs232() statement.
Because you told him to do it, he then initially screwed it up by setting
both APFCON bits =1, which is wrong ! Then later he fixed it.
-------
My point is that you temtronic are leading him down the wrong path much
of the time, and it's taking up a huge number of posts and it's not actually
solving his problems. You need to verify things in the data sheet and the
LST file before you post.
-------------
PrinceNai, this is why I asked for his compiler version. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Jun 27, 2022 4:52 am |
|
|
Compiler version is 5.104
lst is:
Code: | CCS PCM C Compiler, Version 5.104, 26-iun.-22 17:50
*
0000: MOVLP 00
0001: GOTO 00A
0002: NOP
.................... #include <16F1826_uart.h>
.................... #include <16F1826.h>
....................
.................... #device PIC16F1826
....................
.................... #list
....................
.................... #device ADC=8
....................
.................... #FUSES NOMCLR
.................... #FUSES NOBROWNOUT
.................... //#FUSES IESO
.................... //#FUSES FCMEN
.................... #FUSES NOWRT
.................... //#FUSES STVREN
.................... //#FUSES BORV19
.................... #FUSES NOLVP
....................
.................... #use delay(internal=8MHz)
.................... #use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8,stream=PORT1,ERRORS)
0003: BTFSS 11.4
0004: GOTO 003
0005: MOVLB 03
0006: MOVWF 1A
0007: MOVLP 00
0008: MOVLB 00
0009: GOTO 027 (RETURN)
....................
.................... #byte APFCON0 = getenv("SFR:APFCON0")
.................... #bit RXDTSEL = APFCON0.7
.................... #byte APFCON1 = getenv("SFR:APFCON1")
.................... #bit TXCKSEL = APFCON1.0
....................
.................... #define LED PIN_A0
.................... #define DELAY 500
....................
....................
....................
....................
....................
....................
.................... void main()
000A: MOVLW 72
000B: MOVLB 01
000C: MOVWF 19
000D: MOVLB 00
000E: CLRF 20
000F: MOVLB 03
0010: BCF 1F.3
0011: MOVLW 0C
0012: MOVWF 1B
0013: MOVLW A2
0014: MOVWF 1E
0015: MOVLW 90
0016: MOVWF 1D
0017: CLRF 0C
0018: CLRF 0D
0019: MOVLB 02
001A: CLRF 12
001B: CLRF 11
001C: CLRF 14
001D: CLRF 13
.................... {
....................
.................... setup_comparator (NC_NC_NC_NC);
001E: CLRF 12
001F: CLRF 11
0020: CLRF 14
0021: CLRF 13
....................
.................... BIT_clear(RXDTSEL,0); //RX to RB1
0022: BCF 1D.7
.................... BIT_clear(TXCKSEL,0); //TX to RB2
0023: BCF 1E.0
....................
.................... while(TRUE)
.................... {
....................
....................
.................... putc(100); //<<<<< there is the problem ?!?!?
0024: MOVLW 64
0025: MOVLB 00
0026: GOTO 003
....................
.................... output_low(LED);
0027: MOVLB 01
0028: BCF 0C.0
0029: MOVLB 02
002A: BCF 0C.0
.................... //delay_ms(DELAY);
.................... output_high(LED);
002B: MOVLB 01
002C: BCF 0C.0
002D: MOVLB 02
002E: BSF 0C.0
002F: GOTO 024
.................... //delay_ms(DELAY);
....................
.................... }
....................
.................... }
0030: SLEEP
Configuration Fuses:
Word 1: 3984 INTRC_IO NOWDT PUT NOMCLR NOPROTECT NOCPD NOBROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1EFF NOWRT PLL_SW STVREN BORV19 NODEBUG NOLVP |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9377 Location: Greensville,Ontario
|
|
Posted: Mon Jun 27, 2022 6:30 am |
|
|
It's nice to see the listing and it does show that the compiler defaults the comparators to 'off'.
At first glance though, the 'setup_comparators(NC_NC_NC_NC)' appears to be wrong, until you see that 5 lines up a MOVLB 2 was issued. So the compiler keeps track of the BSR and tests to be sure it's the correct one for the next operation. To figure this out you do need to know the PIC instruction set.
So you can delete the 'setup' line based on seeing the compiler did it for you.
I was taught never to assume,always check. In the past ,both CCS and Microchip have redefined what 'defaults' are , and it's not the same for all PICs, all compilers. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19655
|
|
Posted: Mon Jun 27, 2022 7:20 am |
|
|
I have just compiled this code as posted, with his compiler version, and
it merrily puts 'ddddddddddddddddddddddddd.....' to the terminal.
This to a USB to UART adapter set to use 5v serial (I have units that are
jumperable for RS232, 5v, 3.3v).
Which comes back to my questions about how the chip is actually wired,
and he is testing this?.
My wiring was 5v power to pin 5, Gnd to pin 14. 4K7 pull up on pin 4 (should
not be needed with NOMCLR). 5v from bench supply, with 0.1uF ceramic by
the chip. The UART adapter had it's RX pin connected to pin 8 on the PIC,
and it's Gnd connected to the supply ground.
The LED is almost full intensity, since as posted it is turned on for most
of the time. The loop loops every just over 1mSec, and the LED pin goes
off for only a couple of mSec each time round the loop (the LED is left
on when it loops and after the first couple of times round the loop the
UART has to wait for the previous character to transmit).
So the code as posted, works with his compiler. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 27, 2022 7:37 am |
|
|
I also just finished testing it in hardware. It works fine.
I installed CCS vs. 5.104. I used a 16F1827 which is in the same family as
the 16F1826. I used a Picdem2-Plus board, and jumpered the UART Tx and
Rx lines to pins C6 and C7 so I could use the on-board RS-232 circuits.
I also jumpered Pin A0 to pin B0. The board has an LED on that pin.
I also changed the putc '100' to an 'A', so I could definitely see it on TeraTerm.
The LED blinks at a 1 Hz rate. TeraTerm shows the A's:
Quote: | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
It's all totally working.
Here is a photo of the test setup:
Last edited by PCM programmer on Mon Jun 27, 2022 2:56 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19655
|
|
Posted: Mon Jun 27, 2022 7:48 am |
|
|
Two minds with the same thought!...
Mine was a ProtoBoard plug in board. I was able to use the same chip as he
posted.
If you look at what was posted as the compiler output, he had removed
the delays for the LED on this. I compiled this version. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9377 Location: Greensville,Ontario
|
|
Posted: Mon Jun 27, 2022 5:58 pm |
|
|
so.. since his PC with USB-TTL module works (he 'loopbacked ok..) and you've proven the code is good( x2 ! )... I'm wondering if it's as simple having TX of the PIC tied to the TX of the USB module or maybe the grounds is not connected ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19655
|
|
Posted: Tue Jun 28, 2022 1:10 am |
|
|
Exactly.
Which is why I asked ages ago, for him to give us details of how his
hardware is wired. What he is connecting, and to where.
I see in his earlier post he says he is using FT232R. If so, he almost certainly
needs a buffer chip. The FT232R, is available as a board with 5v out, or
as cables with RS232 out. If the latter, he needs an interface between this
and the PIC.
The ones that don't need a buffer are like this:
[url]
https://www.mouser.co.uk/ProductDetail/FTDI/TTL-234X-5V?qs=Mv7BduZupUgF3XwP6s6imA%3D%3D&mgh=1
[/url]
Note specifically that it says 5v.
Ones like this:
[url]
https://cpc.farnell.com/ftdi/ut232r-500/adaptor-cable-usb-rs232-5m/dp/SC14081
[/url]
Will need a buffer chip.
Also there are ones like this:
[url]
https://www.mouser.co.uk/ProductDetail/FTDI/USB-RS232-WE-1800-BT_33?qs=D1%2FPMqvA101O%2FCmqooNxPA%3D%3D&mgh=1
[/url]
Which give 3.3v out, which again won't work without buffering.
More versions won't work, than will.
He needs to post what supply voltage is being used, which actual adapter
he has (ideally a link to the source), and how he has things connected.
As you say jay one 'classic' would be to be connecting TX to TX, not
TX to RX. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
|
|