CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

a compiling error when declare secondary UART port

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

a compiling error when declare secondary UART port
PostPosted: Wed Aug 29, 2012 10:10 pm     Reply with quote

Hi, all
I am new to Microchip, and I am using MPLAB v8.83 with CCS compiler PCD v4.133. I want to use two UART ports in my project, however, when I declare the second one, the compiler shows a error "Error 100 "main.c" Line 24(239,255): USE parameter value is out of range "UART2A" "

My code is
Code:

#if defined(__PCD__)
 #include <33EP512MU814.h>
 #fuses HS,PR,NOWDT,ICSP2,JTAG
 #device ADC=12
 #use delay(clock=20000000) 
 #use RS232(UART1A, STREAM = GSM, BAUD=9600, XMIT = PIN_D0 , RCV = PIN_D1 ,  BITS = 8, STOP = 1, PARITY = N, ERRORS) 
 #use RS232(UART2A, STREAM = MODBUS, BAUD=9600, XMIT = PIN_D2 , RCV = PIN_D3 ,  BITS = 8, STOP = 1, PARITY = N, ERRORS)
 #use i2c(MASTER, I2C1,SCL = PIN_D10, SDA = PIN_D9 , FORCE_SW)
 #endif


I think dsPIC33512MU814 has 4 UART ports, so why the compiler said "UART2" or "UART2A" out of range? Please help~~ thanks a heap!
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 1:35 am     Reply with quote

Get rid of the pin definitions in the #use RS232.
Use #pin select to specify the pins before the #use RS232.

#USE RS232, does not reliably know about pin remapping. Generally, you must use pin select, to specify what pins the UART goes to, and then just tell #use RS232 to talk to UARTx.

However, that doesn't normally give the fault described - the pins just don't work (haven't got the compiler in front of me at present), It is possible there might be an error in the device database, and the compiler doesn't know the chip has four UART's. It is a relatively recent arrival in the database, and as such likely to have problems. If you have the IDE, run the device editor, and see if it shows the UART's.

I'd get rid of the '1A', and '2A' names for the UART's. These are normally reserved for chips that have the UART's available on two sets of pins, with 'UART1' selecting the UART on it's standard pins, and 'UART1A', using the alternate pins. This is not how your chip works, with the UART re-mappable to any one of dozens of pins. The 'A' nomenclature may not therefore be understood. So, just use UART1, UART2 etc., and map the pins first. Also in general with re-mappable peripherals, make sure you set the TRIS on the pins, the compiler tends to not get this right....

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 2:01 am     Reply with quote

Quote:
Also in general with re-mappable peripherals, make sure you set the TRIS on the pins, the compiler tends to not get this right....

The probably unexpected point is that the output control is only overtaken for PPS output functions (e.g. U2TX) but not for input functions (e.g. U2RX). This is by design, not a compiler thing. It corresponds to the fact that multiple input functions can be wired to a single pin. The pin may be even driven as an GPIO or dedicated peripheral output, so you can e.g. implement a loopback.

See datasheet:
Quote:
For input only, peripheral pin select functionality does not have priority over TRISx settings. Therefore, when configuring RPn/RPIn pin for input, the corresponding bit in the TRISx register must also be configured for input (set to ‘1’).


Frank
naughty_mark



Joined: 29 Aug 2012
Posts: 97

View user's profile Send private message

PostPosted: Thu Aug 30, 2012 4:21 pm     Reply with quote

Thank you FvM and Ttelmah, your suggestions are really helpful!

To Ttelmah, I tried to add "#pin_select" before using "#use rs232", it works! at least passed the compile ( I will test if it can really work later Smile ).
After I used "#pin_select" to assign pins to UART2, then I can use "UART2" in "#use rs232" but "UART2A" doesn't work.
And if I didn't use "#pin_select" for UART1 like the code I posted in first poster, I can only use "UART1A" but not "UART1". And if I use "#pin_select" for UART1 and then use "#use rs232", then both "UART1" and "UART1A" work!!
I really got confused on definition between UARTX and UARTXA, as compiler manual says, UARTX means using the dedicated pin and UARTXA means using re-mappable pin, however in dsPIC33EP512MU814, there is no dedicated pins for any UART ports.

Anyway, now it can be compiled and I hope it will work fine. If you can answer my question above to let me get clear view of this function, I do appreciate. Thanks for your guys help.

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Fri Aug 31, 2012 3:43 am     Reply with quote

Yes, it is poorly documented, and confusing.
Basically, it works like this:

1) Using the name UARTx, says 'talk to this set of UART hardware, and assume the default pins'.
2) Using UARTxA, says talk to this set of UART hardware, and map the pins to their alternate address. This only really works with chips that have just two sets of UART pins. It gets worse, because CCS's selection of which is primary, and which is the 'alternate', does not always agree with the data sheet.
You say:
"as compiler manual says, UARTX means using the dedicated pin and UARTXA means using re-mappable pin". This is not what my manual says. It says:
"UART1 Sets the XMIT= and RCV= to the chips first hardware UART.
UART1A Uses alternate UART pins"
Note the use of the word 'alternate', _not_ re-mappable. Quite a few of the chips that appeared before re-mapping became the norm, have two sets of UART pins, referred to as 'primary', and 'alternate'. This is what this for is for.
3) #PIN_SELECT, allows you to assign particular re-mappable hardware peripherals to particular pins.

If you treat the two operations as separate, it seems to work the best:
1) Map the pins you want to the peripheral you want.
2) Then setup the peripheral, and just say 'use the default hardware'.
This way the compiler doesn't try to do too much, and doesn't get (too) confused, and works. Smile

In some senses, part of the problem is CCS trying to be a little 'too smart'. Hiding things like selecting the alternate pins 'inside' the RS232 setup, and then not being able to cope as features get yet more complex.
It is a pity that they didn't separate these at the early stages, just have #use RS232, with UART1, to select the hardware UART, and then a separate line saying 'SELECT_ALTERNATE_UART_PINS', and the #PIN SELECT for chips with more complex re-mappping. Keeping the mapping 'distinct' from the #USE RS232. Currently you have the strange situation with #USE RS232 able to cope with selecting the alternate pins, but not with re-mappable pins.....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group