Skip to content
Snippets Groups Projects
Commit f12a6434 authored by Jonathan BAUDIN's avatar Jonathan BAUDIN
Browse files

Fix Wire and add test with RTC

parent 07c188d6
No related branches found
No related tags found
No related merge requests found

Microsoft Visual Studio Solution File, Format Version 11.00
# Atmel Studio Solution File, Format Version 11.00
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "test", "test.cppproj", "{B3F859AD-E162-4C2F-9684-EAC6932FEC80}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Release|ARM = Release|ARM
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Debug|ARM.ActiveCfg = Debug|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Debug|ARM.Build.0 = Debug|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Release|ARM.ActiveCfg = Release|ARM
{B3F859AD-E162-4C2F-9684-EAC6932FEC80}.Release|ARM.Build.0 = Release|ARM
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
#include "Arduino.h"
#include <Wire.h>
const uint8_t address = 0x68;
uint8_t decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
uint8_t bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setup()
{
Serial5.begin(9600);
Serial5.println("Wire init");
Wire.begin();
// Setting the date
/*
Wire.beginTransmission(address);
Wire.write((uint8_t)0x00); // Init register
Wire.write(decToBcd(0)); // Second
Wire.write(decToBcd(39)); // Minute
Wire.write(decToBcd(11)); // Hours
Wire.write(decToBcd(4)); // Day of week
Wire.write(decToBcd(21)); // Day of Month
Wire.write(decToBcd(5)); // Month
Wire.write(decToBcd(14)); // Year
Wire.endTransmission();
*/
}
void loop()
{
Wire.beginTransmission(address);
Wire.write((uint8_t)0x3F);
Wire.endTransmission();
delay(10);
Wire.requestFrom(address, 7);
/* while(Wire.available())
{
Serial5.print(bcdToDec(Wire.read()));
Serial5.print(" ");
}
Serial5.println();*/
int second = bcdToDec(Wire.read() & 0x7f);
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
int dayOfWeek = bcdToDec(Wire.read());
int dayOfMonth = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
Serial5.print(hour, DEC);
Serial5.print(":");
Serial5.print(minute, DEC);
Serial5.print(":");
Serial5.print(second, DEC);
Serial5.print(" ");
Serial5.print(month, DEC);
Serial5.print("/");
Serial5.print(dayOfMonth, DEC);
Serial5.print("/");
Serial5.print(year,DEC);
Serial5.print(" ");
Serial5.println();
delay(990);
}
......@@ -50,28 +50,28 @@ void TwoWire::begin(uint8_t address) {
uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
{
size_t toRead = quantity;
size_t toRead = quantity + 1;
if(sercom->startTransmissionWIRE(address, WIRE_READ_FLAG))
{
// Connected to slave
while(toRead--)
//for(toRead = quantity; toRead >= 0; --toRead)
{
if( toRead == 0)
if( toRead == 0) // Stop transmission
{
sercom->prepareNackBitWIRE();
sercom->prepareNackBitWIRE(); // Prepare NACK to stop slave transmission
sercom->readDataWIRE(); // Clear data register to send NACK
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP); // Send Stop
}
else
else // Continue transmission
{
sercom->prepareAckBitWIRE();
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_READ);
sercom->prepareAckBitWIRE(); // Prepare Acknowledge
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_READ); // Prepare the ACK command for the slave
rxBuffer.store_char( sercom->readDataWIRE() ); // Read data and send the ACK
}
rxBuffer.store_char( sercom->readDataWIRE() );
}
}
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
return quantity - toRead;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment