Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Is it always required to use set_tris_x function in PIC MCU when using peripherals?

Status
Not open for further replies.

matrixofdynamism

Advanced Member level 2
Joined
Apr 17, 2011
Messages
593
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,681
When using any of the built in peripherals like the ADC or SPI e.t.c specific pins are already designed to be used as input or output for specific functions. e.g using spi_write shall drive the SDO and SCK pins on the PIC. However, should the I/O direction of the involved pins always be set before these functions are called? i.e should I explicitly set the pin numbers corresponding to SDO and SCK as output before I call the spi_write function? The spi_write is found in the CCS PIC C Compiler but I am sure that similar functions also exists in other tools.
 

Yes. Sometimes it is given in datasheet of PIC itself. For example in datasheet of PIC18F452, in UART section, there it is specified that "TRISX bits should be defined before using this module, it should be output For TX and input for RX". So it is good practice to define data direction before using peripherals.
 

Combined with the ANSEL registers, it's good practice to define both (TRIS and ANSEL) even if they are using power-up defaults. Clears up the documentation.
 

It is difficult to say "always". The behaviour of the compiler should be examined, check the asm output produced. If you do not declare anything about port directions, CCS C is willing to set/clear tris registers according to your intention. However, if you declare #use fast_io() you must set tris registers, the compiler does not modify the registers so that your settings stay.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top