Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions examples/ARC_I2C1/master_reader/master_reader.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2016 Intel Corporation. All rights reserved.
// See the bottom of this file for the license terms.

/*
* This sketch is to demonstrate I2C reading from a device, as a bus master. It first makes a request to
* read from the device. Then proceed with reading out one byte at a time and dump in onto the serial term
* for display, in hex. The sketch continue doing the above steps. If the read operation fails, please check
* the connection to the external device: verify the signals, make sure the board and the device share a
* common ground connection.
*
* Please note:
* 1. This sketch makes use of ARC_I2C1. One of the two I2C connections from the ARC core. For the QUARK core I2C
* connection, please refer to the quarkI2C library.
* 2. The ARC_I2C1 connections are not available in the Arduino 101 hardware platform.
* 3. The sketch is accessing an external I2C device with an device number (address) of 8. This address can be
* changed to fit your setup.
*/

#include <ARC_I2C1.h>

void setup()
{
Serial.begin(9600); // start serial for output
while(!Serial); // Wait here till serial terminal is ready/opened

ARC_I2C1.begin(); // join i2c bus
}

void loop()
{

int ret = ARC_I2C1.requestFrom(8, 20); // request 20 bytes from slave device #8
if (ret == 0)
{
Serial.println("read from slave device failed");
}

while (ARC_I2C1.available()) // slave may send less than requested
{
char c = ARC_I2C1.read(); // receive a byte as character
Serial.println(c, HEX);
}
delay(1000);
}


/*
Copyright (c) 2016 Intel Corporation. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/


70 changes: 70 additions & 0 deletions examples/ARC_I2C1/master_writer/master_writer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2016 Intel Corporation. All rights reserved.
// See the bottom of this file for the license terms.

/*
* This sketch is to demonstrate I2C writing to a device, as a bus master. It first makes a request to
* write to the device. Then proceed with write out one byte annd completed the transmission. The sketch
* continues with these steps and increament the byte value each lap. If the write operation fails, please check
* the connection to the external device: verify the signals, make sure the board and the device share a
* common ground connection.
*
* Please note:
* 1. This sketch makes use of ARC_I2C1. One of the two I2C connections from the ARC core. For the QUARK core I2C
* connection, please refer to the quarkI2C library.
* 2. The ARC_I2C1 connections are not available in the Arduino 101 hardware platform.
* 3. The sketch is accessing an external I2C device with an device number (address) of 8. This address can be
* changed to fit your setup.
*/


#include <ARC_I2C1.h>

void setup()
{
Serial.begin(9600); // start serial for output
while(!Serial); // Wait here till serial terminal is ready/opened

ARC_I2C1.begin(); // join i2c bus
}

byte x = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one-letter variable names in sketches, not great for the user. How about something more descriptive, like sendData and receiveData

byte rdata;
void loop()
{
ARC_I2C1.beginTransmission(8); // transmit to device #8
ARC_I2C1.write(x); // sends one byte
int result = ARC_I2C1.endTransmission(); // stop transmitting
if (result == 0)
{
Serial.print("x = ");
Serial.println(x);
}
else
{
Serial.print("transmit failed with error code ");
Serial.println(result);
}
x++;
delay(500);
}


/*
Copyright (c) 2016 Intel Corporation. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/

96 changes: 96 additions & 0 deletions examples/ARC_SPI0/MB85RS64V/MB85RS64V.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2016 Intel Corporation. All rights reserved.
// See the bottom of this file for the license terms.

/*

Please note:
1. This sketch makes use of ARC_SPI0. One of the two SPI connections from the ARC core. For the QUARK core SPI
connection, please refer to the SPI library.
2. The ARC_SPI0 connections are not available in the Arduino 101 hardware platform.
3. The expected Chip ID is 0x04
4. 0xFF denotes connection errors
5. If you need to read the dummy reg value you can do an immediate memory read
*/
// This example uses a FRAM SPI chip
// Dataset is here : https://cdn-shop.adafruit.com/datasheets/MB85RS64V-DS501-00015-4v0-E.pdf
// Op codes:
/* Name Description Op-code
WREN Set Write Enable Latch 0000 0110B
WRDI Reset Write Enable Latch 0000 0100B
RDSR Read Status Register 0000 0101B
WRSR Write Status Register 0000 0001B
READ Read Memory Code 0000 0011B
WRITE Write Memory Code 0000 0010B
RDID Read Device ID 1001 1111B
*/
// The routing on the TT is as follows
/* TPB29 SPI0_SS_MOSI
TPB24 SPI0_SS_MISO
TPB23 SPI0_SS_SCK
TPB22 SPI0_SS_CS0
TPB27 SPI0_SS_CS1
TPB16 SPI0_SS_CS3
*/

// include the SPI library:
#include <ARC_SPI0.h>
const uint8_t dummy_reg = 0x7F;
void setup()
{


Serial.begin(9600); // start serial for output
//while (!Serial) { };

//Move pins to correct Test Point and call the correct macro
//SPI_SE_1 = CS0 -> TBP22
//SPI_SE_2 = CS1 -> TPB27
//SPI_SE_4 = CS3 -> TBP16
// default now to CS 0 uncomment and move pins as needed
ARC_SPI0.begin(SPI_SE_1); // initialize SPI:
//ARC_SPI0.begin(SPI_SE_2); // initialize SPI:
//ARC_SPI0.begin(SPI_SE_4); // initialize SPI:

ARC_SPI0.transfer(dummy_reg);
}

void loop()
{
Serial.print("Transfer OpCode RDID. Return Value = 0x"); // print the character
uint8_t chip_id = ARC_SPI0.transfer(0x9F);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be a bit more consistent with the data type being used for I2C data? one example uses char, the next one uses byte and this one uses uint8_t. Couldn't they all just use char? or maybe uint8_t?

Serial.println(chip_id, HEX); // print the character
delay(1000);

//ARC_SPI0.transfer(dummy_reg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 64 is commented out. Is it needed? if so, explain with another comment. If not, remove.

Serial.print("Transfer OpCode READ. Return Value = 0x"); // print the character
uint8_t mem_Read = ARC_SPI0.transfer(0x3);
Serial.println(mem_Read, HEX); // print the character
delay(1000);

Serial.print("Transfer OpCode RDSR. Return Value = 0x"); // print the character
uint8_t status_Register = ARC_SPI0.transfer(0x5);
Serial.println(status_Register, HEX); // print the character
delay(1000);



}

/*
Copyright (c) 2016 Intel Corporation. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/
39 changes: 23 additions & 16 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@
#######################################
# Datatypes (KEYWORD1)
#######################################
quarkI2C KEYWORD1
quarkI2C KEYWORD1
ARC_SPI KEYWORD1
SPISettings KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
setSpeed KEYWORD2
setAddressMode KEYWORD2
begin KEYWORD2
end KEYWORD2
setSpeed KEYWORD2
setAddressMode KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2
write KEYWORD2
available KEYWORD2
read KEYWORD2
peek KEYWORD2
flush KEYWORD2
onReceive KEYWORD2
onRequest KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2
write KEYWORD2
available KEYWORD2
read KEYWORD2
peek KEYWORD2
flush KEYWORD2
onReceive KEYWORD2
onRequest KEYWORD2
setDataMode KEYWORD2
setClockDivider KEYWORD2
transfer KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################
I2C0 KEYWORD2
I2C1 KEYWORD2
I2C0 KEYWORD2
I2C1 KEYWORD2
ARC_I2C1 KEYWORD2
ARC_SPI0 KEYWORD2
33 changes: 33 additions & 0 deletions src/ARC_I2C1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* ARC_I2C1.cpp is developed based upon the Wire.cpp module.
*
* TwoWire.h - TWI/I2C library for Linux Userspace
* Copyright (c) 2013 Parav https://github.com/meanbot.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Modifications to support Intel Arduino 101
* Copyright (C) 2015 Intel Corporation
*
* Modifications made to support the two I2C connections of the ARC core
* Copyright (C) 2016 Intel Corporation
*/


#include "ARC_I2C1.h"

TwoWire ARC_I2C1 = TwoWire(I2C_SENSING_1);

33 changes: 33 additions & 0 deletions src/ARC_I2C1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* ARC_I2C1.h is developed based upon the TwoWire.h module.
*
* TwoWire.h - TWI/I2C library for Linux Userspace
* Copyright (c) 2013 Parav https://github.com/meanbot.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Modifications made to support the two I2C connections of the ARC core
* Copyright (C) 2016 Intel Corporation
*/

#ifndef _ARC_I2C1_H_
#define _ARC_I2C1_H_

#include "Wire.h"

extern TwoWire ARC_I2C1;

#endif
Loading