Created Tue, 01 Apr 2014 18:38:41 +0000 by czirjek
Tue, 01 Apr 2014 18:38:41 +0000
Hello, i am working on a project for a contest and i have to create a sketch to run my gyroscope connected in port JB. By default the Gyro was connected in pin JE and works fine. I know that the JB pin use DSPI1, i changed that, and the two Int pins to 12 and 13 from 36 and 37 but nothing. In documentation a find something about witch pin to use for SS(slave select) and initial that was set by default, and i don't know where can i change it. I got something in DSPI.cpp -> void DSPI::begin(uint8_t pinT) where the pinT variable is the pin to use for SS instead of the default. Here is my full sketch what is modified but doesn't work, please help me.
/************************************************************************/
/* */
/* GYRODemo.pde -- Example Sketch for GYRO */
/* */
/************************************************************************/
/* Author: Oliver Jones */
/* Copyright (c) 2011, Digilent Inc. */
/************************************************************************/
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/************************************************************************/
/* Module Description: */
/* */
/* This sketch is an example on on how to read the status of a Gyro */
/* with the GYRO library. */
/************************************************************************/
/* Revision History: */
/* */
/* 10/21/2011(Oliver J): Created */
/* */
/************************************************************************/
/************************************************************************/
/* Board Support: */
/* */
/* chipKit Uno32 with Pmod Shield: Header JC */
/* Int1Pin = pin 20 */
/* Int2Pin = pin 21 */
/* (Note: Select Cerebot MX3ck in Tools | Board menu to use this */
/* configuration) */
/* */
/* Cerebot Mx3ck: Header JE */
/* Int1Pin = pin 36 */
/* Int2Pin = pin 37 */
/* */
/* Cerebot Mx4ck: Header JB */
/* Int1Pin = pin 12 */
/* Int2Pin = pin 13 */
/* */
/* Cerebot Mx7ck: Header JD */
/* Int1Pin = pin 28 */
/* Int2Pin = pin 29 */
/* */
/************************************************************************/
#include <DSPI.h>
#include <GYRO.h>
const int Int1Pin = 12;
const int Int2Pin = 13;
const int pinT = 8;//pin to use for SS
int16_t xAxis = 0;
int16_t yAxis = 0;
int16_t zAxis = 0;
int8_t temp = 0;
GYRO myGYRO;
void setup() {
Serial.begin(9600);
Serial.println("Pmod Gyro Demo");
//Set interrupt pins as inputs
pinMode(Int1Pin, INPUT);
pinMode(Int2Pin, INPUT);
pinMode(pinT, OUTPUT);
//setPinSelect(pin);
//myGYRO.setPinSelect(8);
myGYRO.begin(pinT);
//Set XH Threshold Register
myGYRO.setThsXH(0x0F);
//Enable Interrupt
myGYRO.enableInt1(INT1_XHIE);
//myGYRO.disableInt2();
myGYRO.enableInt2(REG3_I2_DRDY);
//myGYRO.disableInt2();
}
void loop() {
//check int1 pin
if(digitalRead(Int1Pin))
{
Serial.println("Int1 was triggerd");
//Read InterruptSrc1 Reg to clear interrupt
myGYRO.getInt1Src();
}
//check int2 pin
if(digitalRead(Int2Pin))
{
Serial.println("Int2 was triggerd");
xAxis = myGYRO.getX();
yAxis = myGYRO.getY();
zAxis = myGYRO.getZ();
temp = myGYRO.getTemp();
Serial.print("X Axis: ");
Serial.println(xAxis, DEC);
Serial.print("Y Axis: ");
Serial.println(yAxis, DEC);
Serial.print("Z Axis: ");
Serial.println(zAxis, DEC);
Serial.print("Temp: ");
Serial.println(temp, DEC);
}
delay(1000);
}
Wed, 09 Apr 2014 21:07:02 +0000
The problem is that both UART1 and SPI1 share pins on connector JB. If you want to use JB for SPI and your convenient micro B USB connector for serial, you will only be able to operate one at a time. So if you were using Serial and needed to access the gyroscope, you would have to call Serial.end(), then re-initialize the gyroscope, communicate with it, call myGYRO.end(), and then re-initialize the serial with Serial.begin(). Sticking with connector JE may be your best bet.
Thu, 10 Apr 2014 06:17:05 +0000
Thank you for information. In the JE pin the gyro works fine but i need to connect a pmod wifi and that is connected in JE pin. This is the reason why i want to connect the Gyro to JB pin. I try to memorize the gyroscope values in an array and close mygyro.end() then initialize the Serial and then with Serial to display these values.
Thank you for help.
Fri, 11 Apr 2014 16:30:19 +0000
Thank you so much! That was the problem and now my sketch is ok and running fine. I just made a synchronization between UART and SPI. Lot of thanks.