This file can be downloaded here ...
https://drive.google.com/drive/folders/0B02sL8YIqsjCeE9Db0RFQlFWdEk?usp=sharing
Enable macros to test ...
#include <Wire.h>
#include <SPI.h>
//#define LED_TEST
//#define ADC_TEST // Pin A0 VCC, GND
//#define GPIO_TEST
//#define PWM_TEST
//#define I2C_TEST //A4 (SDA) and A5 (SCL)
#define SPI_TEST //SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK)
#ifdef SPI_TEST
#define spi_readwrite SPI.transfer
#define spi_read() spi_readwrite(0x00)
int mcp2515_readRegister(const int address)
{
int ret;
int MCP_READ=45;
// MCP2515_SELECT();
spi_readwrite(MCP_READ);
spi_readwrite(address);
ret = spi_read();
// MCP2515_UNSELECT();
return ret;
}
#endif
#ifdef I2C_TEST
#define I2C_ADDRESS 0x50
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
#endif
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
#ifdef LED_TEST
pinMode(13, OUTPUT);
#endif
#ifdef GPIO_TEST
pinMode(2, OUTPUT); //D2
pinMode(12, OUTPUT);//D12
pinMode(13, OUTPUT);//D13
#endif
SPI.begin();
}
void loop() {
// put your main code here, to run repeatedly:
#ifdef LED_TEST
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
#endif
#ifdef ADC_TEST
int sensorValue = analogRead(A0);
Serial.println("value");
Serial.println(sensorValue);
delay(1);
#endif
#ifdef GPIO_TEST
digitalWrite(2, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(2, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(1000);
#endif
#ifdef PWM_TEST
analogWrite(9, 235);//pin D9
#endif
#ifdef I2C_TEST
writeEEPROM(I2C_ADDRESS, 45, 123);
#endif
#ifdef SPI_TEST
{
mcp2515_readRegister(33);
}
#endif
}
No comments:
Post a Comment