Hi all,
I am using Pic16F15324 with Internal Clock at 32MHz ( IDE 7.2.0 ).
I did some test at first by doing classic LED Blinking and that works
Next step is to use UART2 or UART1 and many errors occured. PPS and UART_Remappable library are checked
My code :
PPS_Mapping(09, _INPUT, _RX2_DT2); // Sets pin 09 to be Input, and maps EUSART2
PPS_Mapping(10, _OUTPUT, _TX2_CK2); // Sets pin 10 to be Output, and maps EUSART2
UART2_Remappable_Init(9600) ; // Initialization EUSART2 at 9600 Bauds
PPS trouble :
As defined in online Help you have some identifier according setup BUT "_RX2_DT2" and "_TX2_CK2" are "not valid identifier" I tried many identifier and found 1 working "_RX1" or "_RX2" only but not defined into your list !
UART trouble :
1) expected "constant" but "9600" found
2) By freezing my 2 PPS ligne with "//" compiler return "invalid ASM instrction: *BSF"
In attachment 2 screenshots of code and error.
Best regards.
Pic16F15324 UART and PPS mapping troubles
Pic16F15324 UART and PPS mapping troubles
- Attachments
-
- PPS_mapping.jpg (154.17 KiB) Viewed 4034 times
-
- UART.jpg (156.79 KiB) Viewed 4034 times
Re: Pic16F15324 UART and PPS mapping troubles
Unfortunately, quality of libraries and processor definition files drops with every version . I wouldn't fight with PPS_Mapping - it's less time-consuming and much more code-effective to assign pins manually, likePPS description in processor datasheet is much less likely to have errors then PPS_Mapping.
Error during compilation of UART2_Remappable_Init is due to lack of BAUDCON bits (BRG16, in particular) declaration in processor definition file (P16F15324.pas - may be open in Code Editor with Ctrl-Alt-D combination). Either add the following to this file or place it in your codeand compilation should succeed.
Code: Select all
Unlock_IOLOCK;
RX2DTPPS:=0x11; // Rx2 on RC1 (default)
RC0PPS:=0x11; // Tx2 on RC0 (default)
Lock_IOLOCK;
Error during compilation of UART2_Remappable_Init is due to lack of BAUDCON bits (BRG16, in particular) declaration in processor definition file (P16F15324.pas - may be open in Code Editor with Ctrl-Alt-D combination). Either add the following to this file or place it in your code
Code: Select all
// BAUDCON1, BAUDCON2
const ABDEN = 0; register;
const WUE = 1; register;
const BRG16 = 3; register;
const SCKP = 4; register;
const RCIDL = 6; register;
const ABDOVF = 7; register;
Re: Pic16F15324 UART and PPS mapping troubles
hello Janni,
At first thanks that works !
Little question : i checked UART commands (Init, Read, Write) on both release : Classic and Remappable and both are working. Could you say me if one is more indicated for this kind of Pic16F15324?
Thanks again,
Best regards.
At first thanks that works !
Little question : i checked UART commands (Init, Read, Write) on both release : Classic and Remappable and both are working. Could you say me if one is more indicated for this kind of Pic16F15324?
Thanks again,
Best regards.
- filip.grujcic
- Posts: 822
- Joined: 14 May 2018 08:34
Re: Pic16F15324 UART and PPS mapping troubles
Hello,
Thank you for finding this bug and informing us about it. I have reported it to our developers.
Kind regards,
Thank you for finding this bug and informing us about it. I have reported it to our developers.
Kind regards,
Filip Grujcic
Re: Pic16F15324 UART and PPS mapping troubles
It makes more sense to use UARTx_Init_Remappable as it does not try to correct pin mapping to default like UARTx_Init (calling internally PPS_Mapping which uses 500 code words). As for other library routines, like Read or Write, they're the same, calling same internal functions. Maybe the library looks more impressive with twice that many functions but it only disorients users.axem wrote:Little question : i checked UART commands (Init, Read, Write) on both release : Classic and Remappable and both are working. Could you say me if one is more indicated for this kind of Pic16F15324?
Re: Pic16F15324 UART and PPS mapping troubles
Hi MikroE forum team !
sorry to interfere in this mikroPascal for PIC discussion but ... i am experiencing exactly the same kind of problem using the mikroBasic Pro for PIC (last version V7.6) when trying to remap TX pins of my PIC16F15324.
My code:
Unlock_IOLOCK()
PPS_Mapping_NoLock(5, _INPUT, _RX1)
PPS_Mapping_NoLock(9, _INPUT, _RX2)
PPS_Mapping_NoLock (6,_OUTPUT,_TX1_CK1)
PPS_Mapping_NoLock (10,_OUTPUT,_TX2_CK2)
Lock_IOLOCK()
PPS and UART_remappable are well selected into the library manager.
The compiler declares an error (Identifier " _TX1_CK1" was not declared ) and _TX2_CK2 neither.
how should i proceed iot get this fixed ?
regards
sorry to interfere in this mikroPascal for PIC discussion but ... i am experiencing exactly the same kind of problem using the mikroBasic Pro for PIC (last version V7.6) when trying to remap TX pins of my PIC16F15324.
My code:
Unlock_IOLOCK()
PPS_Mapping_NoLock(5, _INPUT, _RX1)
PPS_Mapping_NoLock(9, _INPUT, _RX2)
PPS_Mapping_NoLock (6,_OUTPUT,_TX1_CK1)
PPS_Mapping_NoLock (10,_OUTPUT,_TX2_CK2)
Lock_IOLOCK()
PPS and UART_remappable are well selected into the library manager.
The compiler declares an error (Identifier " _TX1_CK1" was not declared ) and _TX2_CK2 neither.
how should i proceed iot get this fixed ?
regards
Re: Pic16F15324 UART and PPS mapping troubles
From your code it doesn't look like you're trying to remap - these are all default settings . Except that you used wrong 'pin numbers' - the 'pin number' that, according to Help, one is supposed to find in datasheet, refers to 'PPS Input Selection' or 'PPS Input register' value, not chip pin number (I know, Help is misleading ). For example, pin 5 (RC5) has designated value 0x15 (or _RC5 according to declaration hidden in PPS library). Also, mE developers decided to name the constant corresponding to TXn as _TXnPPS here, not _TXn_CKn.
If you really need to use the PPS library, then the following code should work
Code: Select all
PPS_Mapping_NoLock(_RC5, _INPUT, _RX1)
PPS_Mapping_NoLock(_RC1, _INPUT, _RX2)
PPS_Mapping_NoLock (_RC4,_OUTPUT,_TX1PPS)
PPS_Mapping_NoLock (_RC0,_OUTPUT,_TX2PPS)
Lock_IOLOCK()
Code: Select all
RX1DTPPS=_RC5
RX2DTPPS=_RC1
RC4PPS=_TX1PPS
RC0PPS=_TX2PPS
Lock_IOLOCK()
Re: Pic16F15324 UART and PPS mapping troubles
Thank you very much Janni for these brilliant explanations : how did you discover all these tricks ?
i tested them into my code and the remapping variables (pin names) are now well recognized by the compiler. My compilation works well : very good news.
i tested them into my code and the remapping variables (pin names) are now well recognized by the compiler. My compilation works well : very good news.
Re: Pic16F15324 UART and PPS mapping troubles
Glad to be of help . You're not the first to be mislead by the PPS library explanation in Help.
I'd rather not have to discover them, but mE does not leave us a choice . Constants used in PPS library should be declared in processor definition files and thus visible to users. Unfortunately, they are declared in PPS library which is available only in pre-compiled form (beats me why - it's so simple it could be called primitive). In fact, better (and more code-efficient) approach, like I demonstrated in the second example, would be to explicitly declare all needed constants and explain how to use them.
-
- Posts: 4
- Joined: 25 Feb 2021 21:18
Re: Pic16F15324 UART and PPS mapping troubles
Hey guys,
I'm using the same pic16F15324 from this post with MikroC PRO for PIC v.7.6.0 .
I'm using AN5 (RA5) and AN18 (RC2) and for this second ADC I'm using ADACTPPS = 0x12; //RC2->ADC:ADCACT;
I created my own libraries for use:
Here are my start settings:
The AN5 input has been working well, but the AN18 is behaving wrong, as if there was a pull-up raising this signal.
Does anyone have a tip to give about ADACTPPS in RC2 or how to correctly configure the AN18 in this pic?
I Select only libs Peripheral_Pin_Select and UART_Remappable.
When I select to lib ADC, work correctly. But, I prefer use my lib if possible.
Thank you very much for your valuable help.
I'm using the same pic16F15324 from this post with MikroC PRO for PIC v.7.6.0 .
I'm using AN5 (RA5) and AN18 (RC2) and for this second ADC I'm using ADACTPPS = 0x12; //RC2->ADC:ADCACT;
I created my own libraries for use:
Code: Select all
#define ACQ_US_DELAY 5 // Topic 20.3 ADC Acquisition Requirements explanation this time fixed.
typedef uint16_t adc_result_t;
// result type of a Double ADC conversion
typedef struct
{
adc_result_t adcResult1;
adc_result_t adcResult2;
} adc_sync_double_result_t;
typedef enum
{
channel_TEMPERATURE = 0x5,
channel_RECEPTOR = 0x12,
channel_AVSS = 0x3B,
channel_Temp = 0x3C,
channel_DAC1 = 0x3D,
channel_FVR_BUF1 = 0x3E,
channel_FVR_BUF2 = 0x3F
} adc_channel_t;
void ADC_Init(void)
{
ADCON1 = 0xF0; // Right justify; oscillator ADC RC ; Vdd and Vss Vref
ADACT = 0x00; // ADACT disabled;
ADRESL = 0x00;
ADRESH = 0x00;
ADCON0 = 0x15; // GOnDONE stop; ADON enabled; CHS ANA5;
}
uint16_t ADC_Read (adc_channel_t channel)
{
ADCON0 |= channel<<2; // bit 2-7, select chan 0-20 using 6bits. Is possible because after define ADON and GonDONE; //ADCON0.CHS = channel; // select the A/D channel
ADCON0.ADON = 1; // Turn on the ADC module
delay_us(ACQ_US_DELAY); // Acquisition time delay
ADCON0.GOnDONE = 1; // Start the conversion
while (ADCON0.GOnDONE){} // Wait for the conversion to finish
return ((uint16_t)((ADRESH << 8) + ADRESL)); // Conversion finished, return the result
}
Code: Select all
void Config_Mcu(void)
{
#ifdef P16F15324 // or 23
OSCILLATOR_Initialize(); // 1Mhz intosc
LATA=0;
LATC=0;
TRISA.RA2=0; // led VM
TRISA.RA3=1; // reed switch
TRISA.RA4=0; // poower circuit
TRISA.RA5=1; // an_temperature
TRISC.RC0=0; // led VD
TRISC.RC1=0; // free
TRISC.RC2=1; // an receptor
TRISC.RC3=0; // bus
TRISC.RC4=0; // tx
TRISC.RC5=1; // rx
ANSELA= 0X20; //00100000 AN5 an
ANSELC= 0X14; //00010100 RC2 and RC4(TX) in an
WPUA = 0x00;
WPUC = 0x00;
// Modo 0=Push pull, output is in the middle the two mosfet
ODCONA = 0x00;
ODCONC = 0x00;
// Configura o tempo de subida e descida do sinal, importante no TX e RX:
SLRCONA = 0x37; // 0b0011 0111 (3 não existe no porta)
SLRCONC = 0x3F; // 0b0011 1111 TX e RX =1 subida e descida é limitada a um tempo( modo rapido)
// Configura niveis de sinal ST (Shimitt Trigger) ou TTL para identificar bordas de subida ou descida,usado para gerar interrupcoes:
INLVLA = 0X00; // 00= todos como TTL // 3F; // 0011 1111 // todos pinos PORTA configurado como ST (shimitt triger)
INLVLC = 0B00100000; // 0= TTL 1=ST // Pino RX PORTC5 configurado como ST (shimitt triger) para saber melhor quando é 1 ou 0.
//PPS: Peripheral Pin Select:
Unlock_IOLOCK();
RC4PPS = 0x0F; //RC4->EUSART1:TX1;
RX1DTPPS = 0x15; //00010101 //RC5->EUSART1:RX1;
ADACTPPS = 0x12; //RC2->ADC:ADCACT; TESTAR! ???
Lock_IOLOCK();
DIR_PIC=0;
#endif
}
Does anyone have a tip to give about ADACTPPS in RC2 or how to correctly configure the AN18 in this pic?
I Select only libs Peripheral_Pin_Select and UART_Remappable.
When I select to lib ADC, work correctly. But, I prefer use my lib if possible.
Thank you very much for your valuable help.