CCS News RSS

Click here to view the PDF newsletters. Interested in receiving our newsletters in your inbox? Click here to subscribe.

Tech Note: New i2c functions for the CCS C Compiler!

Monday 06 May, 2019

The CCS C Compiler has added three new functions to the #use i2c() library when setup as an I2C master for transferring data to and from an I2C slave device, the functions are the i2c_transfer(), i2c_transfer_out() and i2c_transfer_in() functions. These functions are added to the CCS C Compiler to support some new devices whose I2C peripheral is not compatible with the legacy i2c_start(), i2c_write(), i2c_read() and i2c_stop() functions. However, these functions are available for all devices when setup as an I2C master using the hardware peripheral or doing a software I2C. Because these functions are supported on all devices, CCS recommends using them instead of the legacy functions for developing code making the code portable to all devices. Another advantage to using these functions, compared to the legacy functions, is that they perform all the I2C steps in a single function call instead of multiple function calls.

The i2c_transfer_out() function transfers data to a slave device use the following:

ack = i2c_transfer_out(SlaveAddr, wData, Count);

The above causes the master to perform an I2C start, send a write command to the specified slave address, send count bytes to slave, perform an I2C stop and return the acknowledge bit. If the acknowledge bit is an ACK, then the transfer is successful. If at any time the slave device NACKs any of the data bytes, the i2c_trasnfer_out() function immediately performs an I2C stop and return a NACK indicating the transfer was unsuccessful.

The i2c_transfer_in() function transfers data from a slave device as follows:

ack = i2c_transfer_in(SlaveAddr, rData, Count);

The above causes the master to perform an I2C start, send a read command to the specified slave address, read count bytes from slave, perform and I2C stop and return the acknowledge bit. If the acknowledge bit is an ACK, then the transfer is successful. When reading data from the a slave device the only byte of data that the slave acknowledges is the read command. If the slave NACKs the read command the i2c_transfer_in() function immediately performs an I2C stop and return a NACK indicating the transfer was unsuccessful.

The i2c_transfer() function is a combination of both the i2c_transfer_out() and i2c_transfer_in() functions, used to transfer data to a slave device or transfer data to and from a slave device. If used to transfer data to a slave device, it works the same as the i2c_transfer_out() function.

When transferring data to and from a slave device, use the following:

ack = i2c_transfer(SlaveAddr, wData, wCount, rData, rCount);

The above causes the master to perform an I2C start, send a write command to the specified slave address, send count bytes to slave, perform an I2C restart, send a read command to the specified slave address, read count bytes from slave, perform and I2C stop and return the acknowledge bit. If the acknowledge bit is an ACK, then the transfer is successful. As with the i2c_transfer_out() and i2c_transfer_in() function, if the slave NACKs any of the bytes being transferred to it the i2c_transfer() function immediately performs an I2C stop and return a NACK indicating the transfer was unsuccessful.

See 241025.c and ds1631.c in the Drivers folder where the CCS C compiler is installed for a couple examples showing how to use the i2c_transfer() function. The 241025.c driver is for a Microchip 24XX1025 I2C Serial EEPROM with 1024K bits of memory, and the ds1631.c driver is Dallas 1631 I2C temperature sensor.


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Tech Note: The CCS C Compiler now supports Dual Core Processors!

Monday 06 May, 2019

The CCS C Compiler now supports the dsPIC33CH family of devices! The dsPIC33CH family are the first dual core PIC®MCUs available from Microchip, which allows the user to run two independent programs on the same device. Additionally each core has separate clock circuits allowing each core to run different clock frequencies, with the Master core's max frequency being 180MHz (90 MIPS) and the Slave core's max frequency being 200MHz (100 MIPS).

Currently devices are available with the Master core having up to 512 Kbytes of flash program memory and up to 48 Kbytes of data RAM, and the Slave core having up to 72 Kbytes of Program RAM (PRAM) and 16 Kbytes of data RAM. Since the Slave core's program memory is PRAM, its actual program is stored in the Master core's Flash program memory and loaded at run time by the Master core into the Slave core's PRAM. The CCS C Compiler provides the functions load_slave_program() and verify_slave_program() for loading and verifying the Slave core's PRAM. See ex_ch_master.c and ex_ch_slave.c for an example of how to build and load a Slave core's program. Additionally, since the Master core and Slave core have separate data RAM, Microchip provides two methods for the cores to communicate with each other. The first method is a series of Mailbox registers, whose direction and protocol can be programmed with configuration fuses to communicate between the cores. The second method is dedicated to read and write FIFO registers that can be used to communicate between the cores. Both are part of the Master Slave Interface (MSI) peripheral and the CCS C Compiler provides several functions for setting it up, checking the status, as well as reading and writing data to and from the mailbox and FIFO registers.

Some features of the dsPIC33CH family are as follows; the Master core has one 16-bit Timer, six DMA channels, eight SCCP peripherals, two UART peripherals, two SPI peripherals, two I2C peripherals, up to two CAN FD peripherals, two SENT peripherals, one CRC peripheral, one QEI peripheral, four CLC peripherals, four 16-bit High-Seed PWM peripherals, a 12-bit ADC with up to 16 channels, and one 12-bit DAC with Analog comparator peripheral. The Slave core has one 16-bit Timer, two DMA channels, four SCCP peripherals, one UART peripheral, one SPI peripheral, one I2C peripheral, one QEI peripheral, four CLC peripherals, eight 16-bit High-Speed PWM peripherals, a 12-bit ADC with two dedicated ADC cores and one shared ADC core with up to 18 channels, and three 12-bit DAC with Analog comparator peripherals.

The SCCP peripheral is newly combined Input Capture, Output Compare, PWM and 32-bit Timer peripherals. This peripheral can be used as either 2 16-bit Timers or a singular 32-bit Timer, a 16-bit or 32-bit Output Compare, a 16-bit or 32-bit Input Capture, or a 16 PWM. Support has been added to #use pwm() for PCD devices that have SCCP peripherals.


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Tech Note: New Message based SPI functions in the CCS C Compiler!

Thursday 29 August, 2019

The CCS C Compiler has added three new functions to the #use spi() library when setup as an SPI master for transferring data to and from a SPI slave device. The functions are the spi_transfer(), spi_transfer_out() and spi_transfer_in() functions. These functions are available for all devices when setup as a SPI master using the hardware SSPx or SPIx peripherals or when doing a software SPI. One advantage of using the spi_transfer() functions is that all the steps for reading or writing data to and from an SPI slave device can be done in a single call to one of the functions instead of multiple calls to the spi_xfer() function. Additionally, if an enable pin is specified in #use spi(), it will set the enable pin to the active state at the start of the transfer, transfer all the bytes, and then set the enable pin to the inactive state at the end of the transfer, instead of toggling the enable pin between the active and inactive states between each call to spi_xfer().

The spi_transfer_out() function transfers data to a slave device and is used as follows:

spi_transfer_out(wData, Count);

The above will cause the master to set the enable pin to the active state, if the enable pin was specified. It will then write count bytes to the slave, and set the enable pin to the inactive state, if enable pin was specified.

The spi_transfer_in() function transfers data from a slave device and is used as follows:

spi_transfer_in(rData, Count);

The above will cause the master to set the enable pin to the active state, if enable pin was specified, read count bytes from slave, and set the enable pin to the inactive state, if enable pin was specified. When using the spi_transfer_in() function it will output a low on the SPI DO pin while the data is being clocked in from the slave device.

The spi_transfer() function simultaneously transfers data to and from a slave device and is used as follows:

spi_transfer(wData, rData, Count);

The above will cause the master to set the enable pin to the active state, if enable pin was specified, write and read count bytes to and from the slave, and set the enable pin to the inactive state, if enable pin was specified.

See 9356.c in the Drivers folder where the CCS C compiler was installed for an example showing how to use the spi_transfer() function. The 9356.c driver is for a Microchip 93C56 Serial EEPROM with 2K bits of memory.

Additionally for devices that have a Direct Memory Access (DMA) peripheral, #use spi() has been updated so that DMA can be used with the spi_transfer() functions when using the hardware SSPx or SPIx peripheral to transfer data to and from SSPx or SPIx peripheral. Using the option USE_DMA in #use spi() will enable using DMA for the spi_transfer() functions, and the options DMA_RX_CHANNEL and DMA_TX_CHANNEL can be used in #use spi() to set the DMA RX and TX channels to something other then the default channels. By default the library uses DMA channel 0 to receive data and DMA channel 1 to transmit data in the PCD compiler. In the PCH compiler, the library uses DMA channel 1 to receive data and DMA channel 2 to transmit data.

When DMA is used, the spi_transfer() functions will not stop code execution while waiting for the spi_transfer() functions to finish the transfer. This is an advantage because it allows the PIC to execute other code while the DMA and SPI peripherals are transferring data to and from the SPI slave. To determine when the SPI transfer has been completed, the function spi_transfer_done() was add to the #use spi() library. Additionally the spi_transfer_clear() was also added the the #use spi() library to clear the interrupt flag used to determine when the transfer is complete. These functions check and clear the interrupt flag for the DMA channel used for receiving from the SPI peripheral. The PCD compiler uses the DMAx interrupt flag and the PCH compiler uses the DMAxDCNT interrupt flag.

When using the USE_DMA option the enable=PIN_xx option is not supported, by the #use spi() library, except for device that have a hardware SSxOUT pin and the device is set up to use the hardware enable pin. In that case, the spi_transfer() function will control the enable pin when the USE_DMA option is used. A PIC18F47K42 is an example of the PIC® that has a hardware controllable enable pin for the SPI peripheral.


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Tech Note: New Advanced RFID driver in the CCS C Compiler!

Thursday 29 August, 2019

CCS has added an new driver, pr9200.c, for communication with a Phychips RED5 UHF RFID reader module. The RED5 is a hybrid module which integrates a Phychips PR9200 high performance UHF RFID reader chipset, TCXO, Balun, Coupler, Saw filter, Power amp and low pass filter. The driver contains all the necessary functions and settings to communicate with the RED5 module to detect, read and write ISO-18000-6C EPC Gen 2 UHF RFID tags.

The driver communicates with the RED5 module via a UART connection, and has defines for selecting the pins to use for the communication along with options. It includes selecting whether to use the PIC® MCU hardware CRC peripheral or a software CRC for doing the CRC16 for messages sent to and received from the RED5 module. The driver contains functions for getting or setting every parameter the RED5 module has, for example, getting and setting the Region, TX Power Level, Session, Frequency Hopping Table, etc., as well as functions for detecting, reading and writing UHF RFID tags. Additionally, almost every function has the option of being cooperative or waiting for a response. For some functions, like setting the TX Power Level, it may be okay to call the function and wait for a response. However in some cases, doing a tag detection, which, depending on the parameter passed to it, can take multiple seconds to finish, it may be preferred to start the process and then return so the PIC can execute other code while waiting for the RED5 module to respond and process those responses as they are received.

CCS's new pr9200.c driver for communicating with a Phychips RED5 mode has all the necessary functionality to get your UHF RFID project started easily and quickly.


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

Tech Note: New Graphic LCD functions in the CCS C Compiler!

Thursday 29 August, 2019

CCS has added some new features to the Interface Designer program. The first new feature includes two new buttons added to the 'Generate' tab, and can be used for generating image and font files. These files are structured so that the data contained in them can be directly passed to the gfx_graphics.c driver's gfx_Loadimage() and gfx_Loadfont() functions. This is useful if a different method for loading images and fonts to the hardware is being used, for example, a USB Flash drive.


Another new feature that was added to Interface Designer is an option on the Settings tab to enable touch debouncing to the C Code generated by Interface Designer. When 'Debounce Touches' is checked, the code that is generated by Interface Designer requires that the area being pressed must be read the specified number of times in a row to be considered a valid touch. This keeps a momentary bad position read by the touch hardware from causing unexpected code execution.


Another new feature added to Interface Designer is a way to reorder the window positions on the windows slide out tray. This is useful because the window that is in the top position of the windows slide out tray is the window that is displayed on power up by the code generated by Interface Designer. This is done by selecting a window in the windows slide out panel, right-clicking the mouse button and selecting 'Move Up'. This will move the selected window up one position. An example of a case were this may be used is if a new splash screen needs to be displayed on power up of an existing project. With this added feature, all that needs to be done to add the new splash screen is to add the image to the project, create a new window and add the image to it, use the 'Move Up' feature to move the new window to the top position, re-generate the library C Code, build and reprogram the display board and download the new image to the display board.


Another new feature added to Interface Designer is an option to clear the display with a solid color before the images for a window are drawn. This is enabled by checking the 'Clear Window First' check box on the 'Window Properties' box on the window images slide out panel. Then you can select the desired color from the color picker box next to it. This is useful in cases where the images added to a window are smaller then then the window and a uniform background color is desired.


The last new feature that was added to Interface Designer are X and Y coordinates that the user's mouse cursor is at when over an image or window. This feature can be seen in the bottom left hand corner of the status panel. This was added to aid in adding areas to images.




Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.

 Displaying 1 to 5 (of 5 articles)   Result Pages:  1