alngTimerModes = {LJ_tmPWM8,LJ_tmRISINGEDGES32}; //Set timer modes
adblTimerValues = {16384,0}; //Set PWM8 duty-cycle to 75%.
alngEnableCounters = {1,0}; //Enable Counter0
//
//eTCConfig (Handle, *aEnableTimers, *aEnableCounters, TCPinOffset,
// TimerClockBaseIndex, TimerClockDivisor, *aTimerModes,
// *aTimerValues, Reserved1, Reserved2);
//
eTCConfig(lngHandle, alngEnableTimers, alngEnableCounters, 4, LJ_tc48MHZ, 0, alngTimerModes, adblTimerValues, 0, 0);
//Read and reset the input timer (Timer1), read and reset Counter0, and update
//the value (duty-cycle) of the output timer (Timer0).
//Fill the arrays with the desired values, then make the call.
alngReadTimers = {0,1}; //Read Timer1
alngUpdateResetTimers = {1,1}; //Update Timer0 and reset Timer1
alngReadCounters = {1,0}; //Read Counter0
alngResetCounters = {1,0}; //Reset Counter0
adblTimerValues = {32768,0}; //Change Timer0 duty-cycle to 50%
//
//eTCValues (Handle, *aReadTimers, *aUpdateResetTimers, *aReadCounters,
// *aResetCounters, *aTimerValues, *aCounterValues, Reserved1,
// Reserved2);
//
eTCValues(lngHandle, alngReadTimers, alngUpdateResetTimers, alngReadCounters, alngResetCounters, adblTimerValues, adblCounterValues, 0, 0);
printf("Timer1 value = %.0f\n",adblTimerValues[1]);
printf("Counter0 value = %.0f\n",adblCounterValues[0]);
4.3.10 - SPI Serial Communication
The U3 (hardware version 1.21+ only) supports Serial Peripheral Interface communication as the master only. SPI is a
synchronous serial protocol typically used to communicate with chips that support SPI as slave devices.
This serial link is not an alternative to the USB connection. Rather, the host application will write/read data to/from the U3 over
USB, and the U3 communicates with some other device using the serial protocol. Using this serial protocol is considered an
advanced topic. A good knowledge of the protocol is recommended, and a logic analyzer or oscilloscope might be needed for
troubleshooting.
There is one IOType used to write/read data over the SPI bus:
LJ_ioSPI_COMMUNICATION // Value= number of bytes (1-50). x1= array.
The following are special channels, used with the get/put config IOTypes, to configure various parameters related to the SPI bus.
See the low-level function description in Section 5.2.15 for more information about these parameters:
LJ_chSPI_AUTO_CS
LJ_chSPI_DISABLE_DIR_CONFIG
LJ_chSPI_MODE
LJ_chSPI_CLOCK_FACTOR
LJ_chSPI_MOSI_PIN_NUM
LJ_chSPI_MISO_PIN_NUM
LJ_chSPI_CLK_PIN_NUM
LJ_chSPI_CS_PIN_NUM
Following is example pseudocode to configure SPI communication:
//First, configure the SPI communication.
//Enable automatic chip-select control.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_AUTO_CS,1,0,0);
//Do not disable automatic digital i/o direction configuration.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_DISABLE_DIR_CONFIG,0,0,0);
//Mode A: CPHA=1, CPOL=1.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_MODE,0,0,0);
//Maximum clock rate (~100kHz).
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_CLOCK_FACTOR,0,0,0);
//Set MOSI to FIO2.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_MOSI_PIN_NUM,2,0,0);
//Set MISO to FIO3.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_MISO_PIN_NUM,3,0,0);
//Set CLK to FIO0.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_CLK_PIN_NUM,0,0,0);
//Set CS to FIO1.
AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chSPI_CS_PIN_NUM,1,0,0);
//Execute the configuration requests.
GoOne(lngHandle);
Following is pseudocode to do the actual SPI communication:
//Transfer the data.
eGet(lngHandle, LJ_ioSPI_COMMUNICATION, 0, &numBytesToTransfer, array);
4.3.11 - I²C Serial Communication
The U3 (hardware version 1.21+ only) supports Inter-Integrated Circuit (I²C or I2C) communication as the master only. I²C is a
synchronous serial protocol typically used to communicate with chips that support I²C as slave devices. Any 2 digital I/O lines are
used for SDA and SCL. Note that the I²C bus generally requires pull-up resistors of perhaps 4.7 kΩ from SDA to Vs and SCL to
Vs, and also note that the screw terminals labeled SDA and SCL (if present) are not used for I²C.
This serial link is not an alternative to the USB connection. Rather, the host application will write/read data to/from the U3 over
USB, and the U3 communicates with some other device using the serial protocol. Using this serial protocol is considered an
advanced topic. A good knowledge of the protocol is recommended, and a logic analyzer or oscilloscope might be needed for
troubleshooting.
There is one IOType used to write/read I²C data:
LJ_ioI2C_COMMUNICATION
The following are special channels used with the I²C IOType above:
LJ_chI2C_READ // Value= number of bytes (0-52). x1= array.
LJ_chI2C_WRITE // Value= number of bytes (0-50). x1= array.
LJ_chI2C_GET_ACKS
The following are special channels, used with the get/put config IOTypes, to configure various parameters related to the I²C bus.
39