To our customers, Old Company Name in Catalogs and Other Documents On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology Corporation, and Renesas Electronics Corporation took over all the business of both companies. Therefore, although the old company name remains in this document, it is a valid Renesas Electronics document. We appreciate your understanding. Renesas Electronics website: http://www.renesas.
Notice 1. 2. 3. 4. 5. 6. 7. All information included in this document is current as of the date this document is issued. Such information, however, is subject to change without any prior notice. Before purchasing or using any Renesas Electronics products listed herein, please confirm the latest product information with a Renesas Electronics sales office.
Application Note CSI to SPI Peripheral Communication in V850ES Microcontrollers ©March 2007. NEC Electronics America, Inc. Printed in USA. All rights reserved. Document no.
CSI to SPI Peripheral Communication in V850ES Microcontrollers ii
SCI to SPI Peripheral Communication in V850ES Microcontrollers Contents 1. Introduction .................................................................................................................................... 1 2. NEC Electronics CSI to SPI Communication.................................................................... 1 2.1 NEC Electronics CSI Communication .................................................................................................. 2 2.2 SPI Communication........
CSI to SPI Peripheral Communication in V850ES Microcontrollers 4.1 4.2 Files for CSI to SPI Demonstration Program ................................................................................... 42 4.1.1 Main.c............................................................................................................................................ 42 4.1.2 Temper.h......................................................................................................................................
SCI to SPI Peripheral Communication in V850ES Microcontrollers 1. INTRODUCTION The purpose of this document is to provide simple examples that will help you better understand functionality of the peripherals included in the NEC Electronics V850ES™ MCU.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Most NEC Electronics MCUs incorporate one or more channels of CSI peripheral, for easy interconnection of devices. This type of interface can also be configured to connect to other devices supporting a 3-wire clocked serial interface. In 3-wire serial I/O communication, data is transmitted or received in eight-bit units; some NEC Electronics MCUs allow transmission in 16-bit units.
SCI to SPI Peripheral Communication in V850ES Microcontrollers When the CSI peripheral is not used, the SCK, SO, and SI I/O pins can be used as port pins. The CSI units are configured using mode registers, control registers, configuration registers, and dedicated hardware logic. Table 1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Figure 1.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 2. Positive-Edge Data Capture Clock Data-In Data Out Data Capture Strobe Master/Slave Figure 3. 2.2 Data Drive Strobe Master/Slave Timing Specifications for Transmit and Receive Operations SPI Communication A typical MCU master with an SPI unit takes a form similar to NEC Electronics CSI units (Figure 4). The SPI Mode Control Register specifies the transfer operation (Figure 5).
CSI to SPI Peripheral Communication in V850ES Microcontrollers When CPHA = 1, the master begin driving data at the first edge of SCK. Therefore, the slave unit uses the first edge of SCK as start of transmission signal. In this clocking mode, the SS_B can remain low (active chip select state) between transmissions. This clocking method may be preferable for one master and one slave configuration. Figure 4.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 5. 7 6 5 4 CPOL SPI Mode Control Register 3 2 1 0 CPHA SPI Mode Control Register 2.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Figure 6. Data-In Data-Out Byte - 1 Byte - 2 Chip Select CPHA = 0 DAPn = 1 Chip Select CPHA = 1 DAPn = 0 2.4 Examples of SPI Peripherals The following examples of SPI peripherals show two temperature sensors, with similar but slightly different SPI hardware. This application note will show how both of these devices can be interfaced to an NEC Electronics MCU without additional hardware. 2.4.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 7. Maxim MAX6627 Remote Temperature Sensor 2N3904 Diode-Connected NPN-Type Transistor The interface to the master unit expects SCK to be low when idle; for an SPI controller, this would require CPOL=0. It uses the first edge of SCK as the data capture strobe and the trailing edge as the data drive strobe; the first data drive strobe is the transition of CS from high to low. For an SPI controller, this would require CPHA=0.
CSI to SPI Peripheral Communication in V850ES Microcontrollers The twelve bits of temperature data is in degrees centigrade, with the upper eight bits (D14 to D7) indicating degrees, and the lower four bits (D6 to D3) indicating sixteenths of a degree. If the lower three bits are masked to zero, the 16-bit signed value can be taken as (temperature in ºC) × 128. Table 3.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 8. MCU Connections to DS1722 Temperature Sensor DS1722 SERMODE CE µC SCLK SDI SDO The polarity of the serial clock depends on its state when CE is asserted. Assuming SCLK is low when CE goes high, the idle state of SCLK is low, which is equivalent to CPOL=0. If SCLK is high when CE goes high, the idle state of SCLK is high, which is equivalent to CPOL=1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Figure 9. Read and Write Cycles From the Master to the DS1722 Temperature Sensor Write from Master to DS1722 Read from DS1722 to Master Table 4 lists the addresses accepted by the DS1722 sensor and the action performed on those addresses. Table 4.
SCI to SPI Peripheral Communication in V850ES Microcontrollers upper seven bits (D14 to D8) indicating degrees, and the lower four bits (D7 to D4) indicating sixteenths of a degree. The device can be programmed using the configuration register for different accuracies, from 8-bit resolution (to the nearest degree) to 12-bit resolution (to the nearest 1/16th of a degree). Lower accuracies provide faster conversion times between readings.
CSI to SPI Peripheral Communication in V850ES Microcontrollers The V850ES MCU’s CSI peripheral is used for communication with the temperature sensor devices, which have built-in SPI peripheral interfaces. For remote sensing of temperature, the MAX6627 temperature sensor uses a diode-connected NPN-type transistor that connects to the temperature-sensing device through a twisted cable and senses the local temperature of the device. Figure 10.
SCI to SPI Peripheral Communication in V850ES Microcontrollers CSI unit can be configured easily for one interface type or another, for this example, we connected the two devices to the same pins, and switched from a type 3 interface (when reading the MAX6627) to a type 4 interface (when reading the DS1722). Two general-purpose I/O port pins are used to drive the MAX6627 Chip Select (/CS) and DS1722 Chip Enable (CE) signals.
CSI to SPI Peripheral Communication in V850ES Microcontrollers which determines where the program will begin on a hardware reset and provides initial setup of system registers before calling the main() function. When Applilet is used to generate a C program for the V850ES MCU, the crte.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Main( ) then calls Temp_Init( ) to initialize the temperature sensors and the CSI/SPI interface used to communicate with the sensors. If an error is detected, an error code is displayed and the program enters an endless loop. To indicate proper initialization, a pair of dashes is shown in the LED. TM00_Start( ) is called to start the TM00 timer for a periodic 1 millisecond interrupt, used for debouncing the input switches.
CSI to SPI Peripheral Communication in V850ES Microcontrollers After processing the switches, main() returns to the top of the program loop to check switch states again. 2.6.3 Temp_Init(): Initialize Temperature Sensor Interface The Temp_Init() routine initializes the temperature sensors to prepare them for reading. Temp_Init() first sets the chip selects for the two temperature sensors to the inactive state, and then calls CSI00_Init() to initialize the clocked serial interface 00 for operation.
SCI to SPI Peripheral Communication in V850ES Microcontrollers The Temp_Init() routine initializes the temperature sensors to prepare them for reading. Temp_Init() first sets the chip selects for the two temperature sensors to the inactive state, and then calls CSI00_Init() to initialize the clocked serial interface 00 for operation. For the MAX6627 temperature sensor (TEMP1), temperature conversions are done once per second, and the most recent conversion is available for reading at any time.
CSI to SPI Peripheral Communication in V850ES Microcontrollers In the CSIC0 clock control register, the CKP0 (clock polarity) bit is set to one and the DAP0 (data phase) bit is cleared to zero. This sets type 3 operation, equivalent to CPOL=0 and CPHA=1 for SPI peripherals. Note that this will be changed by the CSI00_SetType4() routine, and restored by the CSI00_SetType3() routine, to change modes depending on which SPI peripheral is accessed. Figure 14.
SCI to SPI Peripheral Communication in V850ES Microcontrollers 2.6.5 CSI00_SetType3(): Set CSI00 Peripheral for Type 3 Interface The CSI00_SetType3() routine sets the CSI00 peripheral for type 3 interface, for use with the DS1722 temperature sensor. First the CSI0E0 enable bit in the CSIM00 control register is cleared to disable the CSI00 peripheral. This step is necessary when changing bits that control CSI00 operation.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Figure 16. CSI00_SetType4(): Set CSI00 Peripheral for Type 4 Interface E CSI0E0 = 0 (CSIM00.7) to disable CKP0 = 1 (CSIC0.4) DAP0 = 1 (CSIC0.3) for Type-4 CSI0E0 = 1 (CSIM00.7) to enable Return 2.6.7 CSI00_SendData(*txbuf, txnum): Start CSI Data Transmission The CSI00_SendData() routine sets up and starts a transmission operation using CSI00.
SCI to SPI Peripheral Communication in V850ES Microcontrollers The CSI00_SendData() routine sets up and starts a transmission operation using CSI00. The txbuf parameter is a pointer to an array of bytes to transmit, and the txnum parameter is the number of bytes to transmit. First the routine stores the parameters passed in local copies used in the MD_INTCSI00 interrupt service routine.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Figure 18. CSI00_ReceiveData(*rxbuf, rxnum): Prepare To Receive Data on CSI00 G CSI00_RX_LEN = rxnum CSI00_RX_CNT = 0 CSI00_RX_ADDRESS = rxbuf Return 2.6.9 MD_INTCSI00() : Interrupt Service Routine for INTCSI00 The MD_INTCSI00() routine is the interrupt service routine for the INTCSI00 interrupt, which occurs after a byte of data has been transmitted by the CSI00 peripheral.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 19.
CSI to SPI Peripheral Communication in V850ES Microcontrollers The routine sets the CSI00_SendDone flag to FALSE, and writes two dummy bytes by calling CSI00_SendData(txbuf, 2). Because the CSI00 peripheral is in transmit/receive mode, in order to receive data, the transfer must be started by writing a byte of data to the SOTB0L register. This data will be sent out the SO00 output, which is not connected to the MAX6627; the first eight bits of data from the MAX6627 will be clocked in on the SI00 input.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 21. Temp_Read_2(): Read Temperature Sensor 2 (DS1722) I D CALL CSI00_SetType3( ) TEMP2_CS_ON (P9H.6 = 1) Delay 100ns after CS active G CALL CSI00_ReceiveData(rxbuf, 3) txbuf[0] = 0x01 CSI00_SendDone = FALSE CALL CSI00_SendData(txbuf, 3) SendDone == FALSE? F Yes No TEMP2_CS_OFF (P9H.
CSI to SPI Peripheral Communication in V850ES Microcontrollers the rxbuf[0] location. The first received data will not have been driven by the DS1722, so this first receive byte does not contain temperature data. While the dummy data in txbuf[1] is transmitted, the DS1722 will drive the Temperature low byte out on its SDO pin, and this data will be clocked in on SI00.
SCI to SPI Peripheral Communication in V850ES Microcontrollers The data will be shown serially in the two LED digits, scrolling the number through with short delays between shifts. For example the temperature +123.75ºC would be shown as: “1 2” hundreds and tens digits “2 3.” tens and units digits, with decimal point “3. 7” units digit with decimal point, tenths digit “7 5” tenths digit, hundredths digit The temperature –43.275ºC would be shown as “4 ” minus sign, tens digits “4 3.
CSI to SPI Peripheral Communication in V850ES Microcontrollers initialization for I/O ports used. After Applilet produces the basic code, additional code is added by the user to customize the functioning of the program. This section describes how Applilet is set up to produce code for these peripherals, and lists the files and routines produced. Additional files not generated by Applilet, such as those written for temperature sensor access, are also listed.
SCI to SPI Peripheral Communication in V850ES Microcontrollers 2.7.2 Configuring Applilet for CSI00 1. In the Serial Communication Interface box, select CSI00 to open the CSI00 tab. Figure 23. Serial Communication Interface Box 2. The CSI00 tab enables you to control the code generated for the CSI00_Init() routine, and for routines used to read and write data. Figure 24. CSI00 Tab 3.
CSI to SPI Peripheral Communication in V850ES Microcontrollers in two 8-bit cycles. If the MAX6627 sensor were the only device used, you would need to set the data length to 16 bits. 5. In the Data direction box, select MSB to match the temperature sensors. 6. The two temperature sensors use different clock types. The MAX6627 uses a type 4 (clock data mode4), and the DS1722 a type 3 (clock data mode3).
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 26. TM00 Interval Timer Box 2.7.4 Configuring Applilet for I/O Ports 1. Open the Digital I/O Port box to set the individual port pins for input or output, and to specify settings for the pull-up resistors. Figure 27. Digital I/O Port Box 2. On the Port 9-2 tab, set P914 and P915 as outputs. These pins are used as the chip selects for the temperature sensor. (In the program, when these bits are accessed, the reference is to P9H.
CSI to SPI Peripheral Communication in V850ES Microcontrollers 2.7.5 Generating Code With Applilet Once the various dialog boxes are set up, select the “Generate code” option. Applilet will show the peripherals and functions to be generated, and allows you to select a directory to store the source code. When the “Generate” button is pressed, Applilet creates the code in several C-language source files (extension .c), C header files (extension .
SCI to SPI Peripheral Communication in V850ES Microcontrollers File Function Timer.h Header file for timer.c Timer.c Timer 00 functions Timer_user.c User code for INTTM000 interrupt 850.dir Link directive file 2.7.7 Applilet-Generated Files for CSI00 Operation The code generated for CSI00 support are in the files serial.h, serial.c, and serial_user.c. These contain the following items. 2.7.7.1 Serial.h The header file serial.h contains definitions for the CSI00 functions.
CSI to SPI Peripheral Communication in V850ES Microcontrollers 2. void CALL_CSI00_Receive( void ): This routine is called when a reception is complete. Code was added here to set a flag, CSI11_ReceiveDone, to indicate to the main program that receive is complete. The following routines were written and added in serial_user.c; they were not generated by Applilet. 1.
SCI to SPI Peripheral Communication in V850ES Microcontrollers 2.8 Demonstration Platform A demonstration platform was chosen from the NEC development tools available at the time when this document was prepared. In some cases users may be able to duplicate the same hardware by using standard off-the-shelf components along with the NEC MCU of interest. 2.8.
CSI to SPI Peripheral Communication in V850ES Microcontrollers Inter-Brd Connector VDD Voltage Select USB VDD Inter-Brd Connector VPP NEC VDD M-Station Rev-2.
SCI to SPI Peripheral Communication in V850ES Microcontrollers Figure 29. NEC uPD70F3381Y V850ES/KJ1+ A F G Hardware Block Diagram B MAX6627 /CS P915 E Diode-Connected NPN-Type Transistor DxP C SDO D DP SCK LED-1 and LED-2 DxN PDH7 – PDH0 PDLH7 – PDLH0 (PDL15 – PDL8) P914 CE P41/SO00 SDI P40/SI00 SDO DS1722 SERMODE VCC P94 LED-1 P95 LED-2 SW2 SCLK P42/SCK00 SW3 The µPD70F3318Y port pins for LED 1 and LED 2 are listed in Table 8. The PDL port is a 16-bit I/O port.
CSI to SPI Peripheral Communication in V850ES Microcontrollers 2.9 Software Modules The table below shows which files were generated by Applilet, and which of those needed modification to create the demonstration program. The listings for these files are located in section 5. Table 10. Software Modules for the Demonstration Program File Purpose Generated By Applilet Modified By User Main.c Macrodriver.h Crte.s Inttab.s System.inc System.s System_user.c Systeminit.c Port.h Port.c Serial.h Serial.
SCI to SPI Peripheral Communication in V850ES Microcontrollers 3. DEVELOPMENT TOOLS The following software and hardware tools were used in the development of this application note. Table 11. Software Tools Tool Version Comments Applilet E1.46c Source code generation tool for NEC devices V850ESKX1H.mcu V1.33 Applilet MCU configuration for µPD70F3318Y (V850ES/KJ1+) PM Plus V6.10 Project manager for program compilation and linking CA850 V3.
CSI to SPI Peripheral Communication in V850ES Microcontrollers 4. SOFTWARE LISTINGS This application note program is based on specific files and a number of files that are used in other application notes such as “IIC Communication with LCD Module”. For this reason, the files are listed in two separate sections. Since the Applilet code generation tool was used for both programs, there are instances of the same filename, such as serial.h, serial.c, or serial_user.c in each program.
SCI to SPI Peripheral Communication in V850ES Microcontrollers ** ************************************************************************** */ #include "macrodriver.h" #include "port.h" #include "timer.h" #include "serial.h" /* include for temperature sensors */ #include "temper.h" /* includes for M-Station I/O */ #include "sw_vkj1.h" /* switch input */ #include "led_vkj1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** **--------------------------------------------------------------------------*/ void main( void ) { MD_STATUS status; unsigned char sw_val; short temp; /* 16-bit signed temperature value */ sw_init(); led_init(); /* initialize switch variables */ /* initialize LED */ status = Temp_Init(); CheckStatusError(status); initialization */ /* set up temperature sensors */ /* report error if problem with led_out_left(LED_PAT_DASH); read */ led_out
SCI to SPI Peripheral Communication in V850ES Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002 - 2006 ** All rights reserved by NEC Electronics Corporation. ** ** This program should be used on your own responsibility. ** NEC Electronics Corporation assumes no responsibility for any losses ** incurred by customers or third parties arising from the use of this file. ** ** Filename : temper.h ** Abstract : This file implements header for temper.
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** Filename : temper.c ** Abstract : This file implements functions for temperature sensors ** ** Device: uPD70F3318Y ** ** Compiler: NEC/CA850 ** ***************************************************************************** ** */ /* ***************************************************************************** ** ** Include files ***************************************************************************** ** */ #include "macrodriver.
SCI to SPI Peripheral Communication in V850ES Microcontrollers #if (TEMP_DEBUG == 1) int i; /* set up continuous select, 1 buffer mode of operation */ ADM = 0x00; /* clear to reset value to stop converter and generator */ /* also sets select mode, normal conversion, 14.4 us conversion time */ ADMK = 1; /* mask interrupt */ ADS = 0x00; /* no edge detect, software trigger, select ANI0 */ ADCS2 = 1; generator */ /* set ADCS2 (ADM.
CSI to SPI Peripheral Communication in V850ES Microcontrollers CSI00_SendDone = MD_FALSE; INTCSI00 */ CSI00_SendData(txbuf, 2); configuration */ /* set flag false - will be wset true by /* transmit address and data for while (CSI00_SendDone == MD_FALSE) ; /* wait for CSI transfer done */ TEMP2_CS_OFF; /* deselect chip to allow conversion to start again */ #endif return MD_OK; } /* **---------------------------------------------------------------------------** Abstract: ** Function to do Temperature Senso
SCI to SPI Peripheral Communication in V850ES Microcontrollers CSI00_ReceiveData(rxbuf, 2); CSI00_SendDone = MD_FALSE; true by INTCSI00 */ CSI00_SendData(txbuf, 2); transfer (number to receive) */ /* set up to receive two bytes */ /* set flag false - will be wset /* transmit dummy data to start while (CSI00_SendDone == MD_FALSE) ; /* wait for CSI transfer done */ TEMP1_CS_OFF; /* deselect chip to allow conversion to start again */ /* received data is now in rxbuf 0 and 1, with high byte, MSB first, in rx
CSI to SPI Peripheral Communication in V850ES Microcontrollers CSI00_SetType3(); /* set CSI00 interface for Type 3 transfer */ TEMP2_CS_ON; /* select chip to enable reading */ /* delay 400ns between CS true and SCK rise */ /* one NOP takes 50ns at 20MHz, so do eight */ __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); __asm("nop"); CSI00_ReceiveData(rxbuf, 3); is dummy) */ txbuf[0] = 0x01; low byte */ CSI00_SendDone = MD_FALSE; true by INTCSI00 */ CSI00_SendD
SCI to SPI Peripheral Communication in V850ES Microcontrollers ** display temp in degrees in LEDs, turn on decimal point for negative temperature ** **---------------------------------------------------------------------------*/ volatile int dig[5]; /* digits xxx.
CSI to SPI Peripheral Communication in V850ES Microcontrollers } if ( (dig[0] != 0) || (dig[1] != 0) ) { led_dig_left(dig[1]); } else { led_out_left(LED_PAT_BLANK); } } led_dig_right(dig[2]); led_dp_right(1); Temp_Delay_500ms(); led_dig_left(dig[2]); led_dp_left(1); led_dig_right(dig[3]); Temp_Delay_500ms(); led_dig_left(dig[3]); led_dig_right(dig[4]); Temp_Delay_500ms(); led_dig_left(LED_PAT_BLANK); led_dig_right(LED_PAT_BLANK); } 4.1.4 Inttab.
SCI to SPI Peripheral Communication in V850ES Microcontrollers ---------------------------------------------------------------------variable initiate ----------------------------------------------------------------------.section "RESET", text --jr __start .section "NMI", text reti --nmi pin input .section "INTWDT1", text reti --WDT1 OVF nonmaskable .section "INTWDT2", text reti --WDT2 OVF nonmaskable .section "TRAP00", text .globl __trap00 __trap00: reti --TRAP instruction .section "TRAP10", text .
CSI to SPI Peripheral Communication in V850ES Microcontrollers .section "INTTM001", text reti --TM00 and CR001 match .section "INTTM010", text reti --TM01 and CR010 match .section "INTTM011", text reti --TM01 and CR011 match .section "INTTM50", text reti --TM50 and CR50 match .section "INTTM51", text reti --TM51 and CR51 match .section "INTCSI01", text reti --CSI01 transfer complete .section "INTSRE0", text reti --UART0 reception error occurence .
SCI to SPI Peripheral Communication in V850ES Microcontrollers .section "INTWTI", text reti --watchtimer interval .section "INTWT", text reti --watchtimer referemce time .section "INTBRG", text --watchtimer counter BRG and PRSCM match reti .section "INTTM020", text reti --TM02 and CR020 match .section "INTTM021", text reti --TM02 and CR021 match .section "INTTM030", text reti --TM03 and CR030 match .section "INTTM031", text reti --TM03 and CR031 match .
CSI to SPI Peripheral Communication in V850ES Microcontrollers 4.1.5 Systeminit.c /* ***************************************************************************** ** ** This device driver was created by Applilet for the V850ES/KJ1+, V850ES/KG1+, ** V850ES/KF1+, V850ES/KE1+ 32-Bit Single-Chip Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002-2004 ** All rights reserved by NEC Electronics Corporation ** ** This program should be used on your own responsibility.
SCI to SPI Peripheral Communication in V850ES Microcontrollers ** None ** **--------------------------------------------------------------------------*/ void SystemInit( void ) { _rcopy(&_S_romp, -1); __asm("di"); /* disable interrupt */ PORT_Init( ); TM00_Init( ); __asm("ei"); /* Port initiate */ /* TM00 initiate */ /* enable interrupt */ } 4.1.6 Port.
CSI to SPI Peripheral Communication in V850ES Microcontrollers #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define PORT_PM
SCI to SPI Peripheral Communication in V850ES Microcontrollers void PORT_Init( void ); #endif 4.1.7 Port.c /* ***************************************************************************** ** ** This device driver was created by Applilet for the V850ES/KX1+ ** 32-Bit Single-Chip Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002-2004 ** All rights reserved by NEC Electronics Corporation ** ** This program should be used on your own responsibility.
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** None ** **--------------------------------------------------------------------------*/ void PORT_Init( void ) { /* initialize the port registers */ P0 = PORT_P0; P1 = PORT_P1; P3 = PORT_P3; P4 = PORT_P4; P5 = PORT_P5; P6 = PORT_P6; P8 = PORT_P8; P9 = PORT_P9; PCD = PORT_PCD; PCM = PORT_PCM; PCS = PORT_PCS; PCT = PORT_PCT; PDH = PORT_PDH; PDL = PORT_PDL; /* initialize the function registers */ PF3H = PORT_PF3; PF4 = PORT_PF4; PF5 = PORT_PF5;
SCI to SPI Peripheral Communication in V850ES Microcontrollers PMCD PMCM PMCS PMCT PMDH PMDL = = = = = = PORT_PMCD; PORT_PMCM; PORT_PMCS; PORT_PMCT; PORT_PMDH; PORT_PMDL; /*--- initialize the mode control registers ---*/ PMC0 &= ~PORT_PMC0; PMC3 &= ~PORT_PMC3; PMC4 &= ~PORT_PMC4; PMC5 &= ~PORT_PMC5; PMC6 &= ~PORT_PMC6; PMC8 &= ~PORT_PMC8; PMC9 &= ~PORT_PMC9; PMCCM &= ~PORT_PMCCM; PMCCS &= ~PORT_PMCCS; PMCCT &= ~PORT_PMCCT; PMCDH &= ~PORT_PMCDH; PMCDL &= ~PORT_PMCDL; } 4.1.8 Serial.
CSI to SPI Peripheral Communication in V850ES Microcontrollers #define CSIA_AUTORAMSIZE */ #define IIC_RECEIVEBUFSIZE 32 /* CSIA automatic transfer RAM size 32 void CSI00_Init( void ); MD_STATUS CSI00_SendData( UCHAR* txbuf, USHORT txnum ); MD_STATUS CSI00_ReceiveData( UCHAR* rxbuf, USHORT rxnum ); void CALL_CSI00_Receive( void ); void CALL_CSI00_Send( void ); enum TransferMode { Send, Receive }; /* flag set by CALL_CSI00_Send() to signal end of transmission */ extern volatile MD_STATUS CSI00_SendDone;
SCI to SPI Peripheral Communication in V850ES Microcontrollers /* CSI00 Transmission */ UCHAR *CSI00_TX_ADDRESS; USHORT CSI00_TX_CNT; USHORT CSI00_TX_LEN; /* csi00 transmit buffer address */ /* csi00 transmit data number */ /* csi00 transmit data length */ /* CSI00 Reception */ UCHAR *CSI00_RX_ADDRESS; USHORT CSI00_RX_LEN; USHORT CSI00_RX_CNT; /* csi00 recive buffer size */ /* csi00 recive data count */ #define FIX_APPLILET_CSI00_ISR 1 /* define to fix code */ /* **----------------------------------
CSI to SPI Peripheral Communication in V850ES Microcontrollers **---------------------------------------------------------------------------------------------------------** ** Abstract: ** The Application is responsible for transfer data of CSI00 interface. ** ** Parameters: ** txnum: The number of data to transmit(frame number). ** txbuf: Address of transfer buffer.
SCI to SPI Peripheral Communication in V850ES Microcontrollers return MD_OK; } /* **---------------------------------------------------------------------------------------------------------** ** Abstract: ** This function is the high level language interrupt handler ** for the CSI00 transmission completion interrupt (INTCSI00).
CSI to SPI Peripheral Communication in V850ES Microcontrollers 4.1.10 Serial_user.c /* ***************************************************************************** ** ** This device driver was created by Applilet for the V850ES/KX1+ ** 32-Bit Single-Chip Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002-2004 ** All rights reserved by NEC Electronics Corporation ** ** This program should be used on your own responsibility.
SCI to SPI Peripheral Communication in V850ES Microcontrollers void CALL_CSI00_Send( void ) { CSI00_SendDone = MD_TRUE; } /* **--------------------------------------------------------------------------** ** Abstract: ** This function is a call back function to deal with data process after ** some frame(s) data receiving of CSI00 interface. ** ** Parameters: ** None. ** ** Returns: ** None.
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002-2004 ** All rights reserved by NEC Electronics Corporation ** ** This program should be used on your own responsibility. ** NEC Electronics Corporation assumes no responsibility for any losses ** incurred by customers or third parties arising from the use of this file. ** ** Filename : timer_user.
SCI to SPI Peripheral Communication in V850ES Microcontrollers **-----------------------------------------------------------------------------------*/ __interrupt void MD_INTTM000( void ) { /* debounce switch status when timer interrupt occurs */ sw_isr(); /* count down millisecond timer */ if (milliseconds > 0) milliseconds--; } /* set the millisecond timer */ void SetMsecTimer(int time) { milliseconds = time; } /* check the millisecond timer */ BOOL CheckMsecTimer(void) { if (milliseconds > 0) return MD_
CSI to SPI Peripheral Communication in V850ES Microcontrollers OPT : !LOAD ?R V0x7a{ .opt = $PROGBITS ?A .opt; }; TEXT : !LOAD ?RX { .pro_epi_runtime = $PROGBITS .text = $PROGBITS }; DATA ?AX; ?AX; : !LOAD ?RW V0x3ffe000 { .data .sdata .sbss .bss = $PROGBITS ?AW; = $PROGBITS ?AWG; = $NOBITS ?AWG; = $NOBITS ?AW; }; STACK : !LOAD ?RW V0x3ffee00{ .stack = $PROGBITS }; ?AW .stack; __tp_TEXT @ %TP_SYMBOL{TEXT}; __gp_DATA @ %GP_SYMBOL{DATA} &__tp_TEXT{DATA}; __ep_DATA @ %EP_SYMBOL; 4.1.13 Sw_vkj1.
SCI to SPI Peripheral Communication in V850ES Microcontrollers extern void sw_set_debounce(unsigned char count); /* set deboune cound */ extern void sw_isr(void); /* debounce routine, called by timer ISR */ #endif /* _SW_VKJ1_H */ 4.1.14 Sw_vkj1.c /* /* /* sw_vkj1.c - routines for switch input for M-V850ES-KJ1 CPU board on M-Station base board Version: 1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers } /* unsigned char sw_chk(void) */ /* return input from switches, undebounced */ unsigned char sw_chk(void) { return P9L & 0x30; } /* void sw_set_debounce(unsigned char count) */ /* set the debounce counter value */ void sw_set_debounce(unsigned char count) { sw_deb_value = count; /* set new debounce counter value */ sw_deb_count = count; /* set counter to max */ } /* unsigned char sw_get(void) */ /* return debounced switch input */ unsigned ch
SCI to SPI Peripheral Communication in V850ES Microcontrollers /* if we have counted down to zero, we have seen the same sw_new */ /* for debounce count times, it is now the debounced switch value */ if (sw_deb_count == 0) { sw_last = val; sw_deb_count = sw_deb_value; return; } /* if still debouncing, just return */ return; } 4.1.15 Led_vkj1.h /* led_vkj1.h */ /* header for M-V850ES-KJ1 CPU board for LED digit display */ /* Version 1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers #define #define #define #define #define #define LED_PAT_BLANK LED_PAT_DP LED_PAT_DASH LED_PAT_ULINE LED_PAT_OLINE LED_PAT_EQUAL 0xFF 0x7F 0xBF 0xF7 0xFE 0xB7 /*********************************************************************/ /* Export functions */ /*********************************************************************/ extern void led_init(void); /* init ports for LED output */ extern void led_out_right(unsigned char val); /* output valu
SCI to SPI Peripheral Communication in V850ES Microcontrollers PDH0 PDH1 PDH2 PDH3 PDH4 PDH5 PDH6 PDH7 1-A 1-B 1-C 1-D 1-E 1-F 1-G 1-DP R1.17 R1.18 R1.19 R1.20 R1.21 R1.22 R1.23 R1.24 - R2.24 R2.17 R2.18 R2.19 R2.20 R2.21 R2.22 R2.23 SB42 SB35 SB36 SB37 SB38 SB39 SB40 SB41 */ /* NOTE: on M-Station Base V1.0 prototype, PDH0-PDH7 are /* located at ROW4.1-8, and need to be wirewrapped to /* connect to ROW2.17-24 to drive LED1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers void led_out_right(unsigned char val) { PDLH = val; } /* void led_out_left(unsigned char val) */ /* output raw data to left LED */ void led_out_left(unsigned char val) { PDH = val; } /* void led_dp_left(unsigned char on) */ /* turn on or off left DP */ void led_dp_left(unsigned char on) { if (on == 0) PDH = PDH | 0x80; /* set bit 7 high to turn off */ else PDH = PDH & 0x7f; /* set bit 7 low to turn on */ } /* void led_dp_right(unsigned char on)
SCI to SPI Peripheral Communication in V850ES Microcontrollers /* void led_dig(unsigned char num) */ /* display number as hex digits */ /* num - number to display */ /* bits 0-3 in right digit */ /* bits 4-7 in left digit */ void led_dig(unsigned char num) { led_out_right(dig_tab[num & 0x0F]); led_out_left(dig_tab[(num >> 4) & 0x0F]); } /* void led_dig_bcd(unsigned char bcdnum) */ /* display two digits of BCD coded bcdnum */ /* bcdnum - number to display in BCD */ /* 0 - 9 displayed as right decimal digit,
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** V850ES/KF1+ and V850ES/KE1+ 32-Bit Single-Chip Microcontrollers ** ** Copyright(C) NEC Electronics Corporation 2002-2004 ** All rights reserved by NEC Electronics Corporation ** ** This program should be used on your own responsibility. ** NEC Electronics Corporation assumes no responsibility for any losses ** incurred by customers or third parties arising from the use of this file. ** ** Filename : macrodriver.h ** APIlib: V850ESKX1H.
SCI to SPI Peripheral Communication in V850ES Microcontrollers #define MD_MASTER_SEND_END end*/ #define MD_MASTER_RCV_END receive end*/ MD_STATUSBASE+0x11 /*IIC master send MD_STATUSBASE+0x12 /*IIC master /*error list definition*/ #define MD_ERRORBASE 0x80 #define MD_ERROR MD_ERRORBASE+0x0 /*error*/ #define MD_RESOURCEERROR MD_ERRORBASE+0x1 /*no resource available*/ #define MD_PARITYERROR MD_ERRORBASE+0x2 /*UARTn parity error n=0,1,2*/ #define MD_OVERRUNERROR MD_ERRORBASE+0x3 /*UARTn overrun error n=0
CSI to SPI Peripheral Communication in V850ES Microcontrollers # All rights reserved by NEC Electronics Corporation # # This program should be used on your own responsibility. # NEC Electronics Corporation assumes no responsibility for any losses incurred # by customers or third parties arising from the use of this file. # # Filename : crte.s # Abstract : start file for CA850 # APIlib: V850ESKX1H.lib V1.
SCI to SPI Peripheral Communication in V850ES Microcontrollers .extern __ssbss, 4 .extern __esbss, 4 .extern __sbss, 4 .extern __ebss, 4 #---------------------------------------------------------------------------# C program main function #---------------------------------------------------------------------------.extern _SystemInit .extern _main .
CSI to SPI Peripheral Communication in V850ES Microcontrollers #---------------------------------------------------------------------------# RESET handler #---------------------------------------------------------------------------.
SCI to SPI Peripheral Communication in V850ES Microcontrollers st.w add cmp jl r0, [r13] 4, r13 r12, r13 .L12 mov mov cmp jnl #__sbss, r13 #__ebss, r12 r12, r13 .L14 st.w add cmp jl r0, [r13] 4, r13 r12, r13 .L15 .L11: -- clear bss section .L15: .L14: mov ldsr #___PROLOG_TABLE, r12 -- for prologue/epilogue runtime r12, 20 -- set CTBP (CALLT base pointer) -- IRAM clean up -mov 0x3ffd800, r10 mov 0x3fff000, r11 _clear_loop: st.w r0, 0x0[r10] add 4, r10 cmp r11,r10 jnz _clear_loop ld.
CSI to SPI Peripheral Communication in V850ES Microcontrollers --** --** Filename : system.inc --** Abstract : This file implements a device driver for the SYSTEM module --** APIlib: V850ESKX1H.lib V1.33 [24 Sep 2004] --** -- Device: uPD70F3318Y --- Compiler: NEC/CA850 --***************************************************************************** --*/ .set CG_Mainosc, 0x5 .set CG_SECURITY0, 0xff .set CG_SECURITY1, 0xff .set CG_SECURITY2, 0xff .set CG_SECURITY3, 0xff .set CG_SECURITY4, 0xff .
SCI to SPI Peripheral Communication in V850ES Microcontrollers .byte stopped) .byte .byte .byte .byte .byte 0 --Set to option byte (Ring-OSC cannot be 0 0 0 0 0 .section "SECURITY_ID", text .byte CG_SECURITY0 .byte CG_SECURITY1 .byte CG_SECURITY2 .byte CG_SECURITY3 .byte CG_SECURITY4 .byte CG_SECURITY5 .byte CG_SECURITY6 .byte CG_SECURITY7 .byte CG_SECURITY8 .byte CG_SECURITY9 .text .globl .
CSI to SPI Peripheral Communication in V850ES Microcontrollers st.b st.b r11, PRCMD[r0] r11, PCC[r0] nop nop nop nop nop -- PLL start set1 0, PLLCTL[r0] -- PLL work .if 1 -- fix bad code generated by Applilet -- need to set r11 to some value before starting this loop! -- Lock 200 us movea 0x800, r0, r11 .endif __CG_LOOP4: nop nop nop addi -1, r11, r11 cmp r0, r11 bnz __CG_LOOP4 set1 1, PLLCTL[r0] -- enable interrupt stsr 5, r11 andi 0x7f, r11, r11 ldsr r11, 5 -- pop ld.w 0[sp], r11 ld.
SCI to SPI Peripheral Communication in V850ES Microcontrollers ** Filename : system_user.c ** Abstract : This file implements a device driver for the SYSTEM interrupt service routine ** APIlib: V850ESKX1H.lib V1.
CSI to SPI Peripheral Communication in V850ES Microcontrollers **MacroDefine ** ************************************************************************* */ #define TM_TMP0_CLOCK 0x0 #define TM_TMP0_INTERVALVALUE 0x00 #define TM_TMP0_INTERVALVALUE2 0x00 #define TM_TMP0_ONESHOTOUTPUTCYCLE 0x00 #define TM_TMP0_ONESHOTOUTPUTDELAY 0x00 #define TM_TMP0_EXTTRIGGERCYCLE 0x00 #define TM_TMP0_EXTTRIGGERDELAY 0x00 #define TM_TMP0_PWMCYCLE 0x00 #define TM_TMP0_PWMWIDTH 0x00 #define TM_TMP0_CCR0COMPARE 0x00 #define TM
SCI to SPI Peripheral Communication in V850ES Microcontrollers #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define TM05_ONEPULSEDELAY TM50_Clock 0x5 TM50_INTERVALVALUE TM50_SQUAREWIDTH 0x1e TM50_PWMACTIVEVALUE TM51_Clock 0x5 TM51_INTERVALVALUE TM51_SQUAREWIDTH 0x1e TM51_PWMACTIVEVALUE TMH0_Clock 0x3 TMH0_INTERVALVALUE TMH0_SQUAREWIDTH 0x7c TMH0_PWMCYCLE 0x7c TMH0_PWMDELAY 0x3
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** NEC Electronics Corporation assumes no responsibility for any losses ** incurred by customers or third parties arising from the use of this file. ** ** Filename : timer.c ** Abstract : This file implements a device driver for the timer module ** APIlib: V850ESKX1H.lib V1.
SCI to SPI Peripheral Communication in V850ES Microcontrollers CR000 = TM00_INTERVALVALUE; CR001 = 0xffff; } /* **--------------------------------------------------------------------------** ** Abstract: ** start the TM00 counter ** ** Parameters: ** None ** ** Returns: ** None ** ** **--------------------------------------------------------------------------*/ void TM00_Start( void ) { TMC00 = 0x0c; /* interval timer start */ ClrIORBit(TM0IC00, 0x40); /* enable INTTM000 */ } /* **-------------------------
CSI to SPI Peripheral Communication in V850ES Microcontrollers ** MD_OK ** MD_ERROR ** **--------------------------------------------------------------------------*/ MD_STATUS TM00_ChangeTimerCondition(USHORT* array_reg,USHORT array_num) { switch (array_num){ case 2: CR001=*(array_reg + 1); case 1: CR000=*(array_reg + 0); break; default: return MD_ERROR; } return MD_OK; } 92
SCI to SPI Peripheral Communication in V850ES Microcontrollers These commodities, technology or software, must be exported from the U.S. in accordance with the export administration regulations. Diversion contrary to U.S. law prohibited. The information in this document is current as of March 2007. The information is subject to change without notice. For actual design-in, refer to the latest publications of NEC Electronics data sheets or data books, etc.