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

Unable to deactivate CTS

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



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

Unable to deactivate CTS
PostPosted: Tue Jun 11, 2024 2:31 am     Reply with quote

uP=18F16Q41, CCS=5.115, IDE=MPLAB 6.0, OS=Win10

Dear gurus, once again I'm stuck...

The problem is that CTS for UART1 (default PB7) is *working* though it should be off!

Using no buffers in #use-statement should *deactivate* handshaking:
Code:
#use rs232(UART1, BAUD=115200, BITS=8, STOP=1, PARITY=N, ERRORS, STREAM=LTE)


Trying:
Code:
#pin_select U1CTS=NULL
just says "Invalid directive"

Also tried:
Code:
#byte U1CTSPPS = getenv("SFR:U1CTSPPS")
and later U1CTSPPS = 0;

...but that makes no difference, even if trying "CTS_LEVEL=HIGH" in #use rs232

Have no spare inputs that could "fake" a CTS pin.

At my wits end and begging for tips..

All the best:

/Björn
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Jun 11, 2024 4:14 am     Reply with quote

I'd just turn this off yourself. If this works, report it to CCS.

So:
[code]
#byte U1CON2=getenv("SFR:U1CON2")

U1CON2 &= 0xFC; //set low two bits to 0
[code]
bdeb



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

PostPosted: Tue Jun 11, 2024 5:13 am     Reply with quote

Thank you Ttelmah,

Already tried that, does not help.

Probably because #use rs232 "happens" in header file, and does not care if handshake is turned off later in code.

Thank's anyway!

/Björn
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Jun 11, 2024 6:07 am     Reply with quote

You need to talk to CCS.
The problem is not just that it is enabling CTS. It is configuring the UART
incorrectly in several other ways. This chip has different register placements
than the older PIC's, and it appears whoever set up the data configuration,
has not got it quite right. It is writing values into registers that the data
sheet says are 'reserved', and not configuring some other registers at all.

This is a classic problem of jumping on a new chip, before it has been tested
and the problems found. Sad

You might find 5.116 fixes this it has a note that it 'updated definitions for
the newest chips'.
bdeb



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

PostPosted: Tue Jun 11, 2024 6:52 am     Reply with quote

Thank's again!

Will update and post back with results!

I know I'm "bleeding edge" - but just love the new units....
Just the pin_select saved 2 extra board layers.


All the best:

Björn
bdeb



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 12, 2024 5:16 am     Reply with quote

Update:

Tried v 5.117 but still not working.
Sent mail to CCS support.

Keep you posted!

/Björn
bdeb



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

PostPosted: Thu Jun 13, 2024 3:32 am     Reply with quote

Update:

Just tried to set PB7 as analog input.
This makes it work, but feels like a risky hack for production..

Will notify CCS.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Jun 14, 2024 1:26 am     Reply with quote

Provided you can use this pin as analog, this works on your chip since
the ANSEL register disables digital I/O on the pins when they are selected
as analog.
Better possibly (though untested):
Code:

#include <mainCTS.h>   
#pin_select U1TX=PIN_C0
#pin_select U1RX=PIN_C1
#use rs232(UART1, NOINIT, ERRORS, STREAM=LTE)

//UART Baud Rate equals [Fosc*(1+(BRGS*3)]/[(16*(BRG+1))]
#byte U1BRGL = getenv("SFR:U1BRGL")
#byte U1BRGH = getenv("SFR:U1BRGH")
#byte U1CON0 = getenv("SFR:U1CON0")
#byte U1CON1 = getenv("SFR:U1CON1")
#byte U1CON2 = 0x2AD //getenv("SFR:U1C0N2") //does not work
#BIT U1ON = U1CON1.7
#define BAUD 115200

void initUART(void)
{
    int16 BRG;
    //setup IART1 for 115200, no handshake
    U1ON=FALSE; //disable the UART
    U1CON0 = 0b10110000; //8bit TX EN, RX EN, FAST clock, no auto baud
    U1CON2 = 0x80; //Disables flow control one stop bit, no checksum, not inverted
    //Now calculate BRG from clock
    BRG = ((getenv("CLOCK")*4)/(BAUD*16))-1; //This should calculate the BRG value
    U1BRGL=make8(BRG,0); //low byte
    U1BRGH=make8(BRG,1);
    //Now enable the UART
    U1ON=TRUE;
}

void main()
{
    int n;
    initUART();
    while(TRUE) //silly test
    {
        for (n=0;n<255;n++)
           fputc(n,LTE);
    }
}


This turns off the compilers UART initialisation, and goes DIY. What is
interesting is that the getenv on U1CON2 does not work. Since this is
the register with the CTS control bits in it, it probably explains what
is wrong.

When they supply the fix all you do is get rid of the manual INIT, and
turn the initialisation in the #USE RS232.
bdeb



Joined: 05 Nov 2010
Posts: 42
Location: Sweden

View user's profile Send private message Visit poster's website

PostPosted: Thu Jun 27, 2024 12:10 pm     Reply with quote

Update.

The nice guys at CCS came back today with news that this was caused by a MSB from 16-bit multiply that was placed in U1CON2 by mistake.

Compiler fix is on the priority list.


Thank you Ttelmah

/Björn
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Jun 28, 2024 6:57 am     Reply with quote

That is very interesting. They had a problem with the MSB from a multiply
wrapping into another register before. I had tried in the simulator and
found the value in U1CON2 was wrong, but hadn't spotted that it was right
and then changing to wrong.
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