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

Sleep mode for PIC 24HJ64GP504
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Thu Oct 19, 2017 6:09 am     Reply with quote

123_CCS wrote:
There is only this can node with a 120R connected to the canbus. Nothing else.

Put another node on the bus, then try your CAN disable & sleep code on the first.
123_CCS



Joined: 02 Oct 2017
Posts: 10

View user's profile Send private message

PostPosted: Thu Oct 19, 2017 6:28 am     Reply with quote

Ttelmah wrote:
OK. Yes if the delta V between the lines is <0.6v this is the recessive state.

You don't show what is in front of this code?. You do realise you have to switch to config mode _before_ you can switch to disable_mode?.
The config mode acts like a 'lock' for any other mode change.

Okay now I feel stupid, forgot to:
Code:

#pin_select C1TX=PIN_B10
#pin_select C1RX=PIN_B11

Now it does go to sleep mode :-)

Downside is It does not wake up, I do apply a dominant bit to the canbus with a PSU I can see this makes the RX pin on the uC go low, to 0V .

Think I have got the interrupt enabled:
Code:

can_enable_interrupts(WAK);
enable_interrupts(INTR_GLOBAL);       // also tried without this one       

when I go to sleep I do:
Code:

can_set_mode(CAN_OP_CONFIG);  // also tried without this one
can_set_mode(CAN_OP_DISABLE);
sleep(); 

interrupt routine is:
Code:
#INT_CAN1
 void can1_isr(void){
 output_high(LED_RED );

}


I think I am almost there but am missing something.. anyone which can help?
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Thu Oct 19, 2017 7:04 am     Reply with quote

If you don't have anything else on the CAN bus, it won't wake.
It'll only wake if there is CAN activity (or for anything else that is enabled to wake).
123_CCS



Joined: 02 Oct 2017
Posts: 10

View user's profile Send private message

PostPosted: Thu Oct 19, 2017 7:44 am     Reply with quote

I thought the CANbus would wake-up when there is a puls on the RXD pin. So that assumption is not correct?

I also did read this:
Quote:

CiINTE: ECAN Interrupt Enable Register
This register selectively enables/disables 7 main sources of interrupt: transmit buffer interrupt,
receive buffer interrupt, receive buffer overflow interrupt, FIFO almost full interrupt,
error interrupt, wake-up interrupt and invalid message received interrupt (see
Register 21-21). This register is only accessible by the user application when the WIN bit is
cleared (CiCTRL1<0> = 0).

in DS70226C

Do I need to clear this bit before setting the interrupt?
123_CCS



Joined: 02 Oct 2017
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 4:02 am     Reply with quote

-Tried with real CAN device which is trying to send data.
-Measured if the receive pin of the microcontroller changes when making the canbus dominant. This is okay.
-Did read back if the:

C1INTE.wakie bit was set when doing:
Code:

   can_init();
   C1CTRL1.win = 0;
   can_set_mode(CAN_OP_CONFIG); 
   can_enable_interrupts(WAK);
   can_set_mode(CAN_OP_NORMAL);
   C1CTRL1.win= 1;

The bit is set so that is okay also.

Tried numerous other things but nothing seems to wake up from sleep.

Has anyone got a idea how I can fix this?
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 7:09 am     Reply with quote

Have you set the CAN module to disable/sleep mode first?
123_CCS



Joined: 02 Oct 2017
Posts: 10

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 7:36 am     Reply with quote

newguy wrote:
Have you set the CAN module to disable/sleep mode first?



I have tried


CAN_OP_LISTEN
CAN_OP_DISABLE
CAN_OP_CONFIG

like this:

can_set_mode(CAN_OP_DISABLE);
sleep();






none of them seem to work
Code:
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 7:46 am     Reply with quote

You might have to get "down & dirty" with the registers in order to get it to do what you want, as CCS support for that functionality might be lacking.

Section 19.3.2, page 202/390:

Code:
DISABLE MODE

In Disable mode, the ECAN module does not transmit or receive. The module can set the WAKIF bit due to bus activity, however, any pending interrupts remains (sic) and the error counters retain their value.

If the REQOP<2:0> bits (CiCTRL1<10:8>) = 001, the module enters the Module Disable mode. ...
temtronic



Joined: 01 Jul 2010
Posts: 9247
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 23, 2017 10:27 am     Reply with quote

hmm.. I have to ask...

1) does your program work 100% if NOT sleeping ?

2) why go into 'sleep' mode ?

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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