Created Wed, 26 Sep 2012 22:16:59 +0000 by jorheccou
Wed, 26 Sep 2012 22:16:59 +0000
Hi:
I am new in programing the Cerebot MX7CK. I am working on a project that uses 2 serial ports (UART) and want to use a sensor with SPI (Sensor: ADIS16210). I use one of the UART ports as the USB to Serial and the other one I connect it to JF Pmod port. The Cerebot MX7CK user manual tell me that there are 3 SPI port to use, one is in the same port of the UART JF Pmod, the other two are in JE and JD. When I try to connect the senor in JD Pmod port the problem starts. I can’t establish the connection through SPI. I double check the pins and I got them right. I will like to know what am I doing wrong?
Here is the info provided by digilent and microchip.
“The following gives the mapping between SPI signals and connector pins: ï‚•ï€ SS1 JD-01 ï‚•ï€ SDO1 JD-02 ï‚•ï€ SDI1 JD-03 ï‚•ï€ SCK1 JD-04 ï‚•ï€ SS3 JE-01 ï‚•ï€ SDO3 JE-02 ï‚•ï€ SDI3 JE-03 ï‚•ï€ SCK3 JE-04 ï‚•ï€ SS4 JF-01 ï‚•ï€ SDO4 JF-02 ï‚•ï€ SDI4 JF-03 ï‚•ï€ SCK4 JF-04â€
“The DSPI library supports access to all three SPI ports. The DSPI0 object class is used to create an object used to access SPI1, Pmod connector JD. The DSPI1 object class is used to access SPI3, Pmod connector JE, and the DSPI2 object class is used to access SPI4, Pmod connector JF.â€
Here is the code I am using to test it. I am using MPIDE 0023 – 20120903.
#if defined(__AVR__)
#include <avr/io.h>
#endif // AVR
// For PIC32
#if defined(__PIC32MX__)
#include <p32xxxx.h> // This gives all the CPU/hardware definitions
#include <plib.h> // This gives the i/o definitions
// For PIC32
#define __PIC32MX__ 1
// For Uno32
#define __32MX320F128H__ 1
// For Max32/Cerebot MX7cK
#define __32MX795F512L__ 1
#endif // PIC32
//Add the SPI library so we can communicate with the ADIS16210 sensor
#include <SPI.h>
#include <Wire.h>
#include <plib.h>
#include <WProgram.h>
#include <DSPI.h>
#define FLASH_CNT 0x00 // Diagnostics, flash write counter (16-bit binary)
#define SUPPLY_OUT 0x02 // Output, power supply
#define XACCL_OUT 0x04 // Output, x-axis acceleration
#define YACCL_OUT 0x06 // Output, y-axis acceleration
#define ZACCL_OUT 0x08 // Output, z-axis acceleration
#define TEMP_OUT 0x0A // Output, internal temperature
#define XINCL_OUT 0x0C // Output, ±180° x-axis inclination
#define YINCL_OUT 0x0E // Output, ±180° y-axis inclination
#define ZINCL_OUT 0x10 // Output, ±180° z-axis inclination
#define XACCL_NULL 0x12 // Calibration, x-axis acceleration offset null
#define YACCL_NULL 0x14 // Calibration, y-axis acceleration offset null
#define ZACCL_NULL 0x16 // Calibration, z-axis acceleration offset null
#define ALM_MAG_X 0x20 // Alarm, x-axis amplitude threshold
#define ALM_MAG_Y 0x22 // Alarm, y-axis amplitude threshold
#define ALM_MAG_Z 0x24 // Alarm, z-axis amplitude threshold
#define ALM_MAG_S 0x26 // Alarm, system alarm threshold
#define ALM_SMPL_X 0x28 // Alarm, x-axis sample period
#define ALM_SMPL_Y 0x2A // Alarm, y-axis sample period
#define ALM_SMPL_Z 0x2C // Alarm, z-axis sample period
#define ALM_CTRL 0x2E // Operation, alarm control
#define GPIO_CTRL 0x32 // Operation, general I/O configuration and data
#define MSC_CTRL 0x34 // Operation, orientation mode
#define DIO_CTRL 0x36 // Operation, digital I/O configuration and data
#define AVG_CNT 0x38 // Operation, decimation filter configuration
#define SLP_CNT 0x3A // Operation, sleep count
#define DIAG_STAT 0x3C // Diagnostics, system status register
#define GLOB_CMD 0x3E // Operation, system command register
#define LOT_ID1 0x52 // Lot identification, Code 1
#define LOT_ID2 0x54 // Lot identification, Code 2
#define PROD_ID 0x56 // Production identification number
#define SERIAL_NUM 0x58 // Serial Number
DSPI0 spi;
void setup()
{
//Initiate an SPI communication instance.
spi.begin();
//Create a serial connection to display the data on the terminal.
Serial.begin(115200);
}
void loop()
{
spi.setSelect(LOW);
spi.transfer(0x0C);
spi.transfer(0x00);
spi.setSelect(HIGH);
delayMicroseconds(50);
spi.setSelect(LOW);
byte resultHigh = spi.transfer(0x00);
byte resultLow = spi.transfer(0x00);
spi.setSelect(HIGH);
delayMicroseconds(45);
unsigned int result = (resultHigh << 8) | resultLow;
Serial.print(result, DEC);
Serial.print('\n');
delay(500);
}
The previous code was taken partially from another user for the sensor. Thank you for your help.
Wed, 26 Sep 2012 22:38:03 +0000
I leave a picture of the terminal, if it helps.
Tue, 23 Oct 2012 21:02:42 +0000
On the Cerebot MX7cK, the following is how the DSPI ports are mapped to the Pmod connectors:
DSPI0 - connector JD DSPI1 - connector JE DSPI2 - connector JF
I think that you are using the wrong Pmod connector.
Gene Apperson Digilent