DS3234 + Arduino TFT screen using SPI
hey folks! have arduino mega 2560, ds3234 rtc, , arduino tft screen (this one: https://www.arduino.cc/en/guide/tft). both work fine independently, i'm having problems rtc when connect lcd screen well. i'm not familiar spi wondering if here me issue.
the pin connections rtc are:
clk - 52
miso - 50
mosi - 51
ss - 44
for lcd screen:
miso - 50
sck - 52
mosi - 51
cs-ld - 28
dc-ld - 26
reset - 24
if understand correctly, miso, mosi , clk pins should same both devices, chip select pin needs different. devices want communicate needs have cs pin low, , other device needs have high.
i wrote simple program sets rtc time, , displays second. have set cs, dc , reset pins display high, whenever connect display breadboard, both minute , second value become 0. starts working remove display.
code:
what i'm doing wrong here?
i found out rtc keeps count though lcd connected, displays 0. if plug in lcd @ second 2, 3 seconds, , unplug, count resumes 5.
also found out problem miso pin. tried plugging in each pin of lcd individually, , found out miso pin causes time 0.
the pin connections rtc are:
clk - 52
miso - 50
mosi - 51
ss - 44
for lcd screen:
miso - 50
sck - 52
mosi - 51
cs-ld - 28
dc-ld - 26
reset - 24
if understand correctly, miso, mosi , clk pins should same both devices, chip select pin needs different. devices want communicate needs have cs pin low, , other device needs have high.
i wrote simple program sets rtc time, , displays second. have set cs, dc , reset pins display high, whenever connect display breadboard, both minute , second value become 0. starts working remove display.
code:
code: [select]
#include <spi.h>
int chipselect = 44;
int intfreq = 3;
/*display pins*/
int cs = 28;
int dc = 26;
int rst = 24;
#define write_control_reg 0x8e
#define read_control_reg 0x0e
#define write_time_reg 0x80
#define read_time_reg 0x00
typedef struct
{
uint8_t ss;
uint8_t mm;
uint8_t hh;
uint8_t dy;
uint8_t d;
uint8_t m;
uint8_t y;
}timeparams;
void rtc_init(int chipselect, int intfreq)
{
/*
* output frequencies:
* 0: 1hz
* 1: 1.024 khz
* 2: 4.096 khz
* 3: 8.192 khz
* 4: off
*/
/*set chip select pin*/
pinmode(chipselect, output);
//initialize comm
digitalwrite(chipselect, low);
//only change bit 2,3,4,6
spi.transfer(read_control_reg);
byte originalconfig = spi.transfer(0x00);
//end comm
digitalwrite(chipselect, high);
delay(10);
byte configmodifier;
byte newconfig;
//if intfreq 4, turn square wave off
if(intfreq == 4)
{
configmodifier = 0b10111111;
newconfig = configmodifier & originalconfig;
}
else if (intfreq < 4)
{
configmodifier = (intfreq << 3) | 0b01000000; // bit 6 has on
newconfig = configmodifier | (originalconfig & 0b11100011); //only change bits 2,3,4,6
}
digitalwrite(chipselect, low);
spi.transfer(write_control_reg);
spi.transfer(newconfig);
digitalwrite(chipselect, high);
}
static uint8_t convertvalget(uint8_t value)
{
uint8_t convertedvalue = value - 6 * (value >> 4);
return convertedvalue;
}
static uint8_t convertvalset(uint8_t value)
{
uint8_t convertedvalue = value + 6 * (value / 10);
return convertedvalue;
}
void settime(int chipselect, timeparams *timevals)
{
pinmode(chipselect, output);
digitalwrite(chipselect, low);
spi.transfer(write_time_reg);
spi.transfer(convertvalset(timevals->ss));
spi.transfer(convertvalset(timevals->mm));
spi.transfer(convertvalset(timevals->hh));
spi.transfer(convertvalset(timevals->dy));
spi.transfer(convertvalset(timevals->d));
spi.transfer(convertvalset(timevals->m));
spi.transfer(convertvalset(timevals->y));
digitalwrite(chipselect, high);
delay(10);
}
void gettime(int chipselect, timeparams *timevals)
{
pinmode(chipselect, output);
digitalwrite(chipselect, low);
spi.transfer(read_time_reg);
timevals->ss = convertvalget(spi.transfer(read_time_reg));
timevals->mm = convertvalget(spi.transfer(read_time_reg));
timevals->hh = convertvalget(spi.transfer(read_time_reg));
timevals->dy = convertvalget(spi.transfer(read_time_reg));
timevals->d = convertvalget(spi.transfer(read_time_reg));
timevals->m = convertvalget(spi.transfer(read_time_reg));
timevals->y = convertvalget(spi.transfer(read_time_reg));
digitalwrite(chipselect, high);
delay(10);
}
timeparams currenttime = {
39,
29,
11,
4,
5,
7,
17
};
void setup() {
// put setup code here, run once:
pinmode(cs, output);
pinmode(dc, output);
pinmode(rst, output);
pinmode(chipselect, output);
digitalwrite(cs, high);
digitalwrite(dc, high);
digitalwrite(rst, high);
spi.begin();
spi.setbitorder(msbfirst);
spi.setdatamode(spi_mode1);
serial.begin(9600);
rtc_init(chipselect, intfreq);
settime(chipselect, ¤ttime);
}
void loop() {
// put main code here, run repeatedly:
delay(1000);
gettime(chipselect, ¤ttime);
serial.println(currenttime.ss);
}
what i'm doing wrong here?
i found out rtc keeps count though lcd connected, displays 0. if plug in lcd @ second 2, 3 seconds, , unplug, count resumes 5.
also found out problem miso pin. tried plugging in each pin of lcd individually, , found out miso pin causes time 0.
since you're not referencing tft code yet, i'd guess there's wiring issue. can hook tft pins 1 @ time until find offender?
Arduino Forum > Using Arduino > Programming Questions > DS3234 + Arduino TFT screen using SPI
arduino
Comments
Post a Comment