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

PIC24 set environment variable [SOLVED]

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



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24 set environment variable [SOLVED]
PostPosted: Wed Sep 24, 2014 9:51 am     Reply with quote

Device: PIC24HJ256GPxxx
Compiler: 5.026

I am using a hardware UART #1 on my device.

The UART is tied to a serial modem.

To make the modem go into "sleep" mode (low-power), the modem's RX pin needs to be driven low.

Since I am using the HW UART, I cannot force the PIC's TX pin low by simply by calling output_low( PIN_x )... I've tried it and it doesn't work or shall I say, it doesn't let me do that (has no effect).

So, how would I access direct PIC registers to simply tell the PIC's TX pin to go low? And when I want to resume the modem from sleep, tell the PIC's TX pin to go high again using direct register access?

At the moment, I can call, let's say,

#word U1MODE = getenv("SFR:U1MODE");

to get the state of the U1MODE register bits.

So, how do I 1) force a bit low/high and 2) which bit(s) in which register is it?

Thanks,

Benoit


Last edited by benoitstjean on Wed Sep 24, 2014 10:16 am; edited 1 time in total
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Wed Sep 24, 2014 9:59 am     Reply with quote

I think you have to disable/turn off the UART first, then you'll gain control of the RX/TX pins.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Sep 24, 2014 10:15 am     Reply with quote

Thanks newguy but that didn't answer my question. I realize that's what I have to do but I was asking *how* to do it.

Anyhow, I was able to figure it out:


To disable UART1 transmitter and make U1TX pin controlled by port:
Code:

// Read contents of U1STA register
#word U1STA = getenv("SFR:U1STA");

// Assign U1STA bit 10 to FORCE variable
#bit FORCE = U1STA.10

// Force bit 10 of U1STA to 0
FORCE = 0;

At this point, the U1TX pin is now a standard output that can be toggled via output_low/output_high (HW UART no longer has control).


To re-enable UART1 transmitter and give control back to UART1:
Code:

#word U1STA  = getenv("SFR:U1STA");
#bit FORCE = U1STA.10

// Force the bit back to 1
FORCE = 1;

On my modem, I have a flashing LED. When I put the modem in SLEEP mode, the LED stops flashing. When I wake-up the modem, the LED starts flashing again.

So it works.
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