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 support@ccsinfo.com

General advice - first time programmer

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



Joined: 26 Jul 2024
Posts: 2

View user's profile Send private message

General advice - first time programmer
PostPosted: Fri Jul 26, 2024 12:58 pm     Reply with quote

Hi,

I have tested embedded systems before but this is my first time developing firmware itself. I have a few questions. I have a device that already has an existing firmware codebase, I am just trying to take that code and make some modifications in order to add an additional functionality. This device is very simple, it is basically a 1P2T switch and it can be controlled by USB, as well as daisy chained as a slave device on both SPI and I2C interfaces. Here is some additional info of my device and environment:

MPLAB v8.92
PCD compiler
MCU is PIC24FJ256GB206

This is what I'm trying to do:

In the legacy code, the I2C interface of the device was used so that the device can be a slave device. For this revision, I will get rid of the I2C bus ( I believe it's defined in the SW using functions) and instead I will use the 3 lines that used to be used for the I2C address bits as lines that are inputs from an external push button. So basically the switch can be controlled via an external push button.

I noticed that the original code had a few lines that enabled interrupts:

Code:
enable_interrupts(INTR_ALTERNATE);  // BootLoader use the Default INTR
enable_interrupts(INTR_GLOBAL);          // enable interrupts in general to be active
enable_interrupts(INT_SI2C2);


does the global setting mean that any of the I/O pins can now serve as a source of interrupt?

In a different part of the code, those 3 lines that were designated as the I2C address lines were set to inputs using the function:

set_tris().

I will keep that call the same because I will still be using them as inputs from the push button.

I also saw several calls to set_pullup(TRUE, myPin);

But wouldn't we want all pins to be set to TRUE, because otherwise they wouldn't be pulled up and would be floating?

I know these may be very basic questions, so forgive me for that, I am just learning. Any inputs would be appreciated.

Thanks[/code]
Ttelmah



Joined: 11 Mar 2010
Posts: 19336

View user's profile Send private message

PostPosted: Fri Jul 26, 2024 1:52 pm     Reply with quote

You really need to read the chip data sheet.
_each interrupt has two enable bits that control whether it is accepted+.
It's own interrupt enable, and a global enable.
Both have to ve set before an interrupt will be handled.
The 'point' of the global bit is if you want to disable all the interrupts, this
can be disabled, rather than having to turn them all off individually.

On the pull-ups, this depends on the hardware. You need to look at
how the lines are wired. and how they are driven, So if the lines are
driven low, or have external connections they won't want pullups.
it actually uses fractionally less power to drive unused lines low, than
to enable the pullups.
reelthymes



Joined: 26 Jul 2024
Posts: 2

View user's profile Send private message

PostPosted: Fri Jul 26, 2024 1:57 pm     Reply with quote

Thanks for the info. I have been reading the Microchip's datasheet for the PIC24FJ256GB210 Family of devices. I am still learning what some of the lingo means, I also have the book "making embedded systems" which is helping. I will keep reading through the datasheet.
Ttelmah



Joined: 11 Mar 2010
Posts: 19336

View user's profile Send private message

PostPosted: Sat Jul 27, 2024 9:24 am     Reply with quote

Good.
Key is a bit of history. On the older PIC's (12/14/16/18), there is an actual
global interrupt enable bit. On the 16bit PIC's, this is simulated by changing
the priority control. So setting the top three bits of the SRL, disables all the
normal interrupts (but not traps). While clearing these bits enables all
the interrupts/ The compiler retains the 'old' instruction, and using this
just turns the priority up and down (enable/disable).
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