View previous topic :: View next topic |
Author |
Message |
HaveAchat
Joined: 02 Aug 2015 Posts: 16 Location: Australia
|
#pin_select problem on PIC18F47J13 |
Posted: Sun Apr 26, 2020 1:06 am |
|
|
I am having problems getting the hardware USART working with #pin_select.
and yes I did read the sticky note but am still at a loss what my problem is.
Compiler 5.071
If I compile as listed I get an Error 100 ....:USE parameter value is out of range Not a number: TX2
If I flip the PIN definitions it compiles but a soft driver and no interrupt which is my aim.
If somebody could help I would appreciate it.
Code: |
#include <18F47J13.h>
#device ADC=12
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPROTECT //Code not protected from reading
#FUSES SOSC_HIGH //High-power SOSC circuit is selected
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES DSWDTOSC_INT //DSWDT uses INTRC as reference clock
#FUSES RTCOSC_T1 //RTCC uses Secondary Oscillator as reference source
#FUSES DSBOR //BOR enabled in Deep Sleep
#FUSES NODSWDT //Deep Sleep Watchdog Timer disabled
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES ADC12 //ADC is 12-bits
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
#FUSES WPDIS //All Flash memory may be erased or written
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
//!
#use delay(internal=32MHz)
#define Sensor_PWR PIN_B4
#pin_select RX2 = PIN_C1
#pin_select TX2 = PIN_C2
//!#define RX2 PIN_C1
//!#define TX2 PIN_C2
#use rs232(baud = 9600, parity = N, xmit = TX2, rcv = RX2, bits = 8, stream = BT) ///Changed
#INT_RDA2
void RDA2_isr(void) {
// Serial port for Bluetooth Module
int8 c = getc(BT);
putc(c,BT);
}
void main(){
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
while(TRUE){
fprintf(BT,"Main loop\n\r");
output_toggle(Sensor_PWR);
delay_ms(500);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 26, 2020 3:13 am |
|
|
The sticky post on #pin_select at the top of the post list shows how to do it:
Code: |
#pin_select U2RX=PIN_C1
#pin_select U2TX=PIN_C2
#use rs232(UART2, BAUD=9600, ERRORS)
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Apr 26, 2020 3:39 am |
|
|
and, the place to look is the header file for your chip. This a couple of
paragraphs down, lists all the PIN_SELECT 'pin names' that can be used. |
|
|
HaveAchat
Joined: 02 Aug 2015 Posts: 16 Location: Australia
|
|
Posted: Sun Apr 26, 2020 4:05 am |
|
|
Hmmmm that was easy!
In my defence I studied the device file and saw TX2 and RX2 and thought they were the USART designation....
I must of had a boys look and totally missed the U2TX and U2RX for the past week, what can I say.
Another problem is I did not use the default #use rs232(UART2, definition. It doesn't work any other way. Two point of ignorance!
So, a question to help my understanding please?
What does TX2 and RX2 refer to?
Once again many thanks for the assistance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Apr 26, 2020 7:20 am |
|
|
Yes, that is a case of CCS choosing to use one 'part' of the MicroChip name.
TX2, works for synchronous transmit, and RX2 for synchronous receive,
but not for the standard async TX/RX. Really should be DT2/RX2.
Designed totally to confuse... |
|
|
|