Beginner question

What does it usually mean when touching a wire with your finger makes the circuit work?

In this case: It's a DS3234 RTC (SPI interface) on a breadboard, driven by an Uno. It reports the correct values on the very first read after resetting the Uno; then junk.... unless I touch the MOSI pin. Then it works perfectly.

Usually you are introducing noise into the circuit while doing that.
Noise isn't supposed to help a lot.

In this case i suspect the noise has a pull up effect.
You probably need to add pull up resistors to the signal pins.
If that doesn't help, try pull down resistors.

If you are touching GND level besides the specified pin, you need the pull downs.

According to the datasheet, the clock polarity needs to be 1 and the clock phase needs to be set accordingly. This corresponds to SPI_MODE2 or SPI_MODE3. Use SPI.setDataMode(SPI_MODE2) or SPI.setDataMode(SPI_MODE3). One of these should work.

I was only touching MOSI via a wire, nothing else (other than my chair).
A 1K pulldown makes it work in mode 1.

The datasheet states:

        "4MHz SPI Bus Supports Modes 1 and 3"

        "Either clock polarity can be used. The clock polarity is determined
         by the device based on the state of SCLK when CS goes low."

I tried mode 2 and it didn't work, either with or without a pulldown resistor.
Mode 3 appears to work fine, with or without the resistor.

I had breadboarded it once before and it worked in mode 1. It may have been right on the edge of functioning, I don't know.

Could this just be a symptom of using a breadboard?

Do you have a schematic you can show us? That would certainly be helpful.

Is it on a proven breakout board or is this a standalone part? Are you using the square wave output? Do you have a battery connected?

Could this just be a symptom of using a breadboard?

Definitely. Longer signal paths will adversely affect the signal's characteristics (rise/fall/delay). Sometimes a slower clock rate is required for breadboard testing.

I would stick with SPI_MODE3 for compliance with the datasheet.

Note that 4MHz is the maximum clock rate of this IC and is also the default clock rate for SPI. You could still get fast data transfer if you set the clock rate to 1MHz or 2MHz by using SPI.setClockDivider(). For a 16MHz Ardino board, use SPI.setClockDivider(SPI_CLOCK_DIV8) for SCK=2MHz or SPI.setClockDivider(SPI_CLOCK_DIV16) for SCK=1MHz.

syntaxterror:
Do you have a schematic you can show us? That would certainly be helpful.

It's hooked up exactly as shown on the first page of the datasheet, "Typical operating circuit".
The part is soldered to an SOIC-20 to DIP adapter board. That board is plugged into a standard breadboard and VCC(5V), GND, SCK, MOSI and MISO are all driven by an Uno R3 via 10cm long male/male breadboarding wires. There is also a 3V coin battery attached to the chip and a 0.1uF capacitor between VCC and GND, just as in the datasheet diagram.

dlloyd:
I would stick with SPI_MODE3 for compliance with the datasheet.

I will since it's working that way (at the moment). It should work in mode 1 as well, as per the datasheet. I wonder if noise is affecting the chip's auto-select feature, preferentially?

jboyton:
It's hooked up exactly as shown on the first page of the datasheet, "Typical operating circuit".
The part is soldered to an SOIC-20 to DIP adapter board. That board is plugged into a standard breadboard and VCC(5V), GND, SCK, MOSI and MISO are all driven by an Uno R3 via 10cm long male/male breadboarding wires. There is also a 3V coin battery attached to the chip and a 0.1uF capacitor between VCC and GND, just as in the datasheet diagram.

Where do your chip select and reset pins connect?

syntaxterror:
Where do your chip select and reset pins connect?

I forgot that one. CS is connected to digital pin 10 on the Uno.

And I lied about matching the diagram exactly. RST is not connected to anything, INT/SQW is not connected to anything. All of the NC pins are grounded as in the diagram.

Alright. Reset should pull itself up when not connected. If you aren't using SQW, then that won't matter a great deal either. So far so good, I think.

Clearly, you are introducing some sort of potential when touching the circuit, which happens to be just what it needed to start running. If I were you, and I hadn't done so already, I'd try saving what hair remains on my head by pulling out and reinserting every single breadboard jumper wire. Especially if they were new wires.

Do you have any measuring equipment available?

It should work in mode 1 as well, as per the datasheet. I wonder if noise is affecting the chip's auto-select feature, preferentially?

For the Arduino, mode 1 has CPOL=0. However, the datasheet page 18 shows *CPOL=1 for writes, therefore you cannot write to the IC in mode 1.
*CPOL is the clock-polarity bit set in the control register of the host microprocessor.

syntaxterror:
Do you have any measuring equipment available?

Only a DMM. I'm looking for an inexpensive (used) oscilloscope so I'm not working in the dark at times like these.

dlloyd:
For the Arduino, mode 1 has CPOL=0. However, the datasheet page 18 shows *CPOL=1 for writes, therefore you cannot write to the IC in mode 1.
*CPOL is the clock-polarity bit set in the control register of the host microprocessor.

The datasheet also shows CPOL=0 for writes. And it says:

        "Either clock polarity can be used. The clock polarity is determined
         by the device based on the state of SCLK when CS goes low."

But I have to admit that it's working well in mode 3 and not so well in mode 1. I just don't understand why exactly.

edit:
Maxim makes this clear yet again in application note 4005. And they describe what they mean by the SPI modes in app note 502. And yet, searching the web I found a number of instances where people simply couldn't get the DS3234 to work in mode 1 and used mode 3 instead. For what that's worth, anyway. Mine seems quite happy now in mode 3, while sharing the bus with two other devices which use mode 0.

Your wire might be broken inside the plastic, and touching it temporarily connects it.

michinyon:
Your wire might be broken inside the plastic, and touching it temporarily connects it.

I was touching a second wire that I added simply to give myself a single point to touch. This was after noticing that touching groups of wires seemed to affect the function. I replaced the wire that connected Uno pin 11 (MOSI) to the RTC but that had no effect. And when I then connected the RTC to an ATtiny chip it also failed with mode 1 and is working with mode 3.

I suppose it's possible that Maxim is wrong about their own chip, but I'm not entirely comfortable with just assuming that.

Since you have a DMM on hand, I think you should measure continuity in all your connections to start with. Odds are they're good, but there is absolutely nothing more annoying than troubleshooting a circuit you THINK you know is okay. If at all possible, shorten the breadboard wires, especially ground.

Hi,
can you post a picture of your project so we can see what you have, as well as a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks Tom... :slight_smile:
It sounds like you have not got all your gnds connected.

TomGeorge:
It sounds like you have not got all your gnds connected.

+1
I've got a sneaky, tingling suspicion about poor grounding also.

TomGeorge:
can you post a picture of your project so we can see what you have, as well as a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I added circuitry once I got it working in mode 3. So now it's different, although still a bird's nest of breadboard wires. Basically, instead of an Uno driving the RTC it's now an ATtiny running the RTC, a pressure sensor and an OLED display. It's hard to take a good picture; I'm not sure these will help:

And a schematic: