Jump to content
Sign in to follow this  
altineller

DS3234 SPI problem with TM4C123

Recommended Posts

Hello,

 

I am having trouble using a SPI DS3234 RTC with Energia and TivaC series launchpad.

 

I am using the ds3234 library at https://github.com/rodan/ds3234 which is originally written for arduino.

 

I modified few settings in the initialization, tried few things, but have not had any luck. The module will not talk spi at all, and I get 1900.00.00 00:00:00 for date all the time.

 

Here is the relevant code from the init section:

void DS3234_init(const uint8_t pin, const uint8_t ctrl_reg)
{
    pinMode(pin, OUTPUT); 
    SPI.setModule(2);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV32); 
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE3);
    DS3234_set_creg(pin, ctrl_reg);
    delay(10);
}

First off I am setting spi port 2, before spi.begin. I tried all clock_dividers. The ds3234 supports upto 4mhz spi speed, so considering 80mhz clock speed for tivac board, I am using a div32 divider. I also scanned all of the dividers. I tried spi_mode 1 and 3 also. I also checked with an oscilloscope, that I am indeed talking with SPI2 port. (I can see the clock and cs lines with little spikes, when the tiva-c sends commands).

 

For some reason the SPI port in the TivaC is unable to talk with this RTC chip. I could not figure out why.

 

I tested the same code on a MSP430F5529 with the RTC connected to SPI0 port, and it worked as expected.

 

Here is the relevant part for that one: (I only commented out the setModule statement, and used the div8 divider)

void DS3234_init(const uint8_t pin, const uint8_t ctrl_reg)
{
    pinMode(pin, OUTPUT); 
    //SPI.setModule(2);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8); 
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE3);
    DS3234_set_creg(pin, ctrl_reg);
    delay(10);
}

I also found a forum post at http://forum.43oh.com/topic/9016-ds3234-rtc-peek-poke/ which complains about not being able to peek / poke the internal SRAM of the ds3234 - but unfortunately was not answer. I am speculating this too arises from similar SPI trouble.

 

Any ideas/recomendations/help greatly appreciated,

 

Best Regards,

C.

Share this post


Link to post
Share on other sites

Do you set the chip select (CS or SS) pin?

 

Hello,

 

Yes, I configured the CS pin as output. Relevant init code as follows:

const int CS = PB_5;

void DS3234_init(const uint8_t pin, const uint8_t ctrl_reg)
{
    pinMode(pin, OUTPUT); 
    SPI.setModule(2);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV16); 
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE3);
    DS3234_set_creg(pin, ctrl_reg);
    delay(100);
}

For some reason it will not read  values the right way. I put a serial.print(char); in the for loop where it reads time, and figured out it will read only 0x00.

 

The code works on the msp430g5529.

 

Best regards,

C.

Share this post


Link to post
Share on other sites

I second this question. As I recall the ds3234 is also active high on CS / CE.

 

Hello, yes I set the CS as explained in my previous reply.

 

I also checked the ds3232 sheet, and for CS it is active when it is low.

 

Untitled-plZLRNVz.1467733236.png

 

 

I got this from the ds3234 datasheet,

 

And on codewise:

void DS3234_set_addr(const uint8_t pin, const uint8_t addr, const uint8_t val)
{
    digitalWrite(pin, LOW);
    SPI.transfer(addr);
    SPI.transfer(val);
    digitalWrite(pin, HIGH);
}

the CS pin is pulled low, and then spi transfer is made in two operations always, then CS pin is pulled high.

 

Is this correct?

 

Best regards,

C.

Share this post


Link to post
Share on other sites

Hello, yes I set the CS as explained in my previous reply.

 

I also checked the ds3232 sheet, and for CS it is active when it is low.

 

Untitled-plZLRNVz.1467733236.png

 

 

I got this from the ds3234 datasheet,

 

And on codewise:

void DS3234_set_addr(const uint8_t pin, const uint8_t addr, const uint8_t val)
{
    digitalWrite(pin, LOW);
    SPI.transfer(addr);
    SPI.transfer(val);
    digitalWrite(pin, HIGH);
}

the CS pin is pulled low, and then spi transfer is made in two operations always, then CS pin is pulled high.

 

Is this correct?

 

Best regards,

C.

OK, I must have missed that. However above I'll assume "ds3232" was a typo ? As the ds3232 is an I2C RTC ;) I just happen to be using a ds3232 in a project right now . . .

Share this post


Link to post
Share on other sites

Have you tried a lower SPI speed, as the TM4C123 runs at 80 MHz?

 

To do so, change SPI_CLOCK_DIV32 for SPI_CLOCK_DIV64 or SPI_CLOCK_DIV128.

yes i did. i tried all the spi dividers upto div128.

 

tomorrow, i am going to hookup a logic analyzer to spi pins and try to debug and post the results.

 

 

Sent from my iPhone using Tapatalk

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×