PIC32MX cannot change select TRIS bits - microcontroller

hopefully I have the right forum here.
Firstly:
Processor: PIC32MX795F512L (on the chipKIT mx32 dev board)
IDE: MPLAB X IDE v2.26
Pogrammer/Debugger: PicKIT 3
I am trying to set some of the PORT pins to outputs so I can bit bang a communication protocol to another device. However, when I run the PIC using the pickit 3 as a debugger, I find that some of the TRIS bits won't toggle to 0.
This is an issue I am having with just TRISF and TRISG so far, and I have seen some mention of it in other posts, but no solution.
The pins I have tried to toggle are:
TRISF4 (SDA3A/SDI3A/U3ARX/PMA9/CN17/RF4)
TRISG3 (D-/RG3)
TRISG2 (D+/RG2)
here is an example of how I am doing it.
ODCDCLR = 0xFFFF;
ODCFCLR = 0xFFFF;
TRISDCLR = 3<<14;
TRISFCLR = 3<<5;
What could be some causes for a sticky TRIS bit?

If you look at page 36 of the datasheet, you will see that G2 and G3 are input-only when used as digital I/O instead of USB. Excerpt below:
Similarly, if you have UART3 enabled, RF4 will be an RX input.
You need to make sure you enable/disable the peripherals sharing those pins and read the datasheet very carefully. It's a complete PITA sometimes, but I've never found the datasheet to be wrong - just sometimes things are well hidden!

Two big causes are a pin configured for analog and a pin configured for some other function, like JTAG.
For F and G, you would set ANSELF = 0 and ANSELG = 0. For JTAG you'd need to check your data sheet and then set the appropriate configuration bit.
I haven't checked the data sheet for your specific device so I can't be more definitive.
Update:
See Roger Rowland's answer. No substitute for reading the data sheet!

Related

How to use Arduino 9 axes motion shield

I've just bought a brand new Uno rev3 and 9-axes-motion shield, however there doesn't seem to be any documentation or working examples :/
All the top search results seem to refer to a previous version of the code (where its referred to as NAxisMotion where as now its NineAxesMotion.
Regardless, I'm getting calibration states of 0 on all sensors using the example codes with the below library and from the few examples i can find traces of
Are there some pin differences, or interrupt values which are different to the defaults in the code?
https://github.com/arduino-org/arduino-library-nine-axes-motion
The internet seems completely barren on this shield :/
Update to make example questions clear
What is the pin out/pin usage for the 9-axes-motion-shield?
How can I determine if my I2C interface is "working" (sending/receiving data)
Any other debug advice?
I'm not sure how you do web research but this is what I found within 1 minute:
https://create.arduino.cc/projecthub/techmirtz/using-9-axes-motion-shield-with-arduino-e71107
https://hackaday.io/project/26925-using-9-axes-motion-shield-with-arduino
https://www.instructables.com/id/Using-9-Axes-Motion-Shield-With-Arduino/
and many other forum discussion. So I wouldn't agree that the Internet is barren on this shield.
There is also a full documentation on the Bosch IC for which this shield is basically just a breakout board for which Arduino provides the schematics.
https://www.bosch-sensortec.com/bst/products/all_products/bno055
So what else can you wish for?
This was difficult to solve.
The default pins specified inside NineAxesMotion.h are wrong for the way boards are configured.
See this PR: https://github.com/arduino-org/arduino-library-nine-axes-motion/pull/6
Look at your board and see how pins 4 or 2, and 3 or 7 are jumpered to the Interrupt and Reset pins respectively.
The defaults these days seem to be Interrupt = 2, Reset = 7.
I've updated the defaults in that PR and improved the comments and readme. If you don't want to use my PR, you need to hack NineAxesMotion.h and change the RESET_PIN and INT_PIN definitions to your pinout.

What is the difference between SPI and QPI (in embedded)?

In my project, I am using Winbond W25Q64 64-MB Serial flash, When i read datasheet of this serial flash there is two type:
SPI(W25Q64 FLASH ID :- 0xEF4017) and QPI(W25Q64FV FLASH ID :- 0xEF6017).
I know SPI very well, but first time i heard about QPI. So i have some Questions-
1.What is the difference's between SPI and QPI?
2.Can i use QPI communication type Flash(using SPI)?
3.What is the main feature's of QPI and what is QPI(a Communication Protocol or something else)?
Description of the QPI protocol is part of the datasheet (I have added the link into your question).
Judging from the description there, it does use four data lines for I/O (in contrast to SPI where one line is designated for input and another for output), thus saving clock cycles (compared to standard SPI) as one byte can be transfered in 2 cycles only. Available commands seems to be different too compared to SPI mode.
This chip supports some "extended" SPI modes (called Dual and Quad SPI) where more data lines are used for sending data to master. These are triggered by standard SPI command, but data transfer differs. See the details in the datasheet.
It is not compatible with "standard" SPI, and I am not sure if there is any common MCU supporting this mode. It looks similar to the SD card / SDIO, but I have no idea how much is it (dis)similar.
Yes, you can. The standard SPI (one input and one output data line) seems to be the default interface. The extended SPI modes are used in response to particular SPI commands only and the QPI mode has to be explicitly enabled by respective SPI command (see figure 3 in page 12).
In addition:
Quad SPI and QPI instructions require the non-volatile Quad
Enable bit(QE) in Status Register-2 to be set. When QE=1,
the /WP pin becomes IO2 and /HOLD pin becomes IO3.
...
QE bit is required to be set to a 1 before issuing an “Enable QPI
(38h)” to switch the device from Standard/Dual/Quad SPI to QPI,
otherwise the command will be ignored. When the device is in QPI mode,
QE bit will remain to be 1. A “Write Status Register” command in QPI
mode cannot change QE bit from a “1” to a “0”.
Advantage is faster data transfer at the same clock frequency. Details of the protocol are well described in the datasheet including timing plots etc.

Arduino and electronics beginner beginnering

I'm working through a set of beginner exercises with the Arduino Uno microcontroller. (A generic one, though, as this is what I've been supplied with.)
The program I'm running, which alternates between sending 1's and 0's to serial output depending on the state of a momentary switch, has set pin 2 to be the input for the switch. But. Whilst wiring up, I accidentally plugged the jumper cable in to pin 3 initially, and found it still mostly sent the 1's when the button was pushed. Some 0's, yet mostly 1's.
Initially I thought maybe it was just the board was a bit dodgy, but thought I'd experiment a bit. Plugging into pin 3 instead of pin 2 still fairly consistently sent 1's when the button was pushed, though the 1's flowed a little bit less consistently than when it was in pin 2. In pin 2 it was completely consistent by comparison. So I tried pin 4, but with that one there's no response at all.
Am I right in presuming the program's readings seems to get a little bit less responsive the further away I move the cable from the pin that I've programmed to act as input? Can anyone help me understand why this happens?
It's probably quite obvious that I'm new to electronics. :)
The program I've got uploaded to the board is as follows:
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1); // delay in between reads for stability
}
Floating pins are prone to noise. If you are not actually connecting anything to pin 2, you will be reading noise. Any wire connected to pin 2 (even connections on the board) will act like an antenna and pick up noise. You should always use the pin number that you are physically connecting in situations like these.
Leaving input pins open makes the microcontroller read a floating value which swings between 0 to 1. Also when wiring a switch to any pin, make sure to hook some pull-down resistor to make the input 0.
These are common for many electronics and proper notice to be taken while designing circuits of your own.
You need to look into datasheet where described functions of the pins.
The pins of MCU can be assigned various functions through special registers.
Two most common functions of the pins are input and output. MCUs provide internal pull-up and pull-down resistors which when used properly significantly simplifies electronic schemas.
If the input activated as input without any pull-??? then it's state is not defined and can be used as initiator of random number generator. Due this reason it is better to define what is default state of the input pin by connecting pull-??? resistors.
In Arduino IDE you are not limited to functions provided -- you still can use register manipulation directly, you just need to learn internals of the MCU.
If you do it properly then 2kbit program very often can be made as small as a few hundred bytes and it will work hundred times faster.
Operating registers in C is not much different from assembly, in C++ you get right away significant overhead -- although some benefits of registers still can be significant.
Libraries hide from programmers internals of MCU what is nice as it simplifies the programming and does not require to understand how MCU works, what registers are changed in what sequence.
But when you know hardware in and out -- you can squeeze from small MCU what is not possible with use of libraries (code will just not fit into the chip). MCUs are not that complicated (Atmel) to learn about it's internals -- benefits are significant.
Knowledge is a power which many avoid.

Sending output from arduino to picaxe

I am doing a class project involving an Arduino Uno and a Picaxe 14m2.
I am in the middle of attempting to code a program for the Arduino Uno that will allow me to send and output value to the input on the Picaxe.
So in layman's, this is what I wish to achieve:
I want the Arduino to check a sensor, and if the sensor returns a specific value. (- I know this part, but not the next.) I then want the Arduino to send a value (HIGH, or 1 .. something like that) as an output to one of the Picaxe input pins. I then need the Picaxe to notice a value has been sent, and then do something else.
Any help would be appreciated.
Thanks.
If you are looking for that, you may want to specify what kind of PICAXE you have.
Since there is a difference in the types of these chips.
After that you may wanna look over the datasheet of the PICAXE so that you can find the instructions set and the type of program memory you have, "EEPROM....".
After that:
List your Is/Os, inputs and outputs.
Set your source code editor.
Write the source code and burn it to the PICAXE program
memory.(C, Assembly...)
Write your Arduino code, setting the Is/Os and telling the
Arduino how to deal with the signals in and out.(C language)
Make a circuit diagram for the hardware you are going to connect
between both chips.
Don't forget to see the loading effects on both the Arduino and
the PICAXE, because you don't want to burn your project hardware
after all.
Test your project and note that you will have to troubleshoot
both software and hardware whenever a problem occurs.
I suggest that you use the Oscilloscope to test the signals going in or coming out of both circuits + the sensor's signal.
For any extra thing you need the PICAXE to do, use If statements, because they are not so technical to implement and they are easy to write and troubleshoot.
For your scheme, you are actually making the Arduino give instructions to the PICAXE through a variable signal coming from a sensor.
^send me feedback and I will help more.
You will probably want to look into using UART (aka Serial) or i2c communication.
Serial communication should work with any PICAXE and Arduino, While i2c Will only work if you are using the X2 Series PICAXE Chips. i2c's main advantage is when using multiple slave devices (plus the master device, i.e. more than just 2 devices total) in which you can use the same two wires for up to around 128 devices. Serial (UART) communication is simpler, and only needs one wire (plus a common ground) to send data one way, it is what i'll show for the rest of this answer
Here is the manual entry for serial input for the PICAXE, and Here's the entry for serial output from the Arduino. The code you will need given your question will be something like the following:
For the arduino:
void setup(){
Serial.begin(9600);
}
void loop(){
if (conditionMet){ //whatever the condition is in your code
int bytesSent = Serial.write(“HIGH”); //send the string “HIGH"
}
}
and for the PICAXE:
main:
serin 6, T9600, ("HIGH") 'uses qualifier to look for exact message "HIGH"
'do whatever when criteria met
goto main

I cannot find fritzing 2x3 pin header

How can I get an 2x3 pin header (used for ISP programming for atmega, for example), to appear in Fritzing? I cannot find it in the parts list.
Please correct me, if I'm wrong, but I think the 2x3 pin header is still in the fritzing standard library. I searched in the part toolbar "2x3" and find the header with the following description:
AVR ISP 6 Pin This is the reduced ISP connector for AVR programming.
Common on Arduino. This footprint will take up less PCB space and can
be used with a 10-pin to 6-pin adapter such as SKU: BOB-08508

Resources