/*
Digital Pot Control
This example controls an Analog Devices AD5206 digital potentiometer.
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
A - connect this to voltage
W - this is the pot's wiper, which changes when you set it
B - connect this to ground.
The AD5206 is SPI-compatible,and to command it, you send two bytes,
one with the channel number (0 - 5) and one with the resistance value for the
channel (0 - 255).
The circuit:
* All A pins of AD5206 connected to +5V
* All B pins of AD5206 connected to ground
* An LED and a 220-ohm resisor in series connected from each W pin to ground
* CS - to digital pin 8 (SS pin) P2.0
* SDI - to digital pin 14/15 (MOSI pin USI/USCI) P1.6/P1.7
* CLK - to digital pin 7 (SCK pin) P1.5
created 10 Aug 2010
by Tom Igoe
modified 2 May 2012 - changed SS pin
by Rick Kimball
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
*/
// include the SPI library:
#include <SPI.h>
// set pin 8 as the slave select for the digital pot:
const int slaveSelectPin = PB_5;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
void loop() {
// go through the six channels of the digital pot:
for (int channel = 0; channel < 6; channel++) {
// change the resistance on this channel from min to max:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, level);
delay(10);
}
// wait a second at the top:
delay(100);
// change the resistance on this channel from max to min:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, 255 - level);
delay(10);
}
}
}
int digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
Das ist der denn Energia drin hat.
Ich habe im anderen auch direkt SPI.begin(); eingefügt hat trotzdem nichts gebracht
PS. Ich habe auch eine andere Libirary gefunden wo bezug auf Texas und Energia genommen wurde:
Enrf24_TXdemo
/*
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>
Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin(); // Defaults 1Mbps, channel 0, max TX power
dump_radio_status_to_serialport(radio.radioState());
radio.setTXaddress((void*)txaddr);
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(str_on);
radio.print(str_on);
radio.flush(); // Force transmit (don't wait for any more data)
dump_radio_status_to_serialport(radio.radioState()); // Should report IDLE
delay(1000);
Serial.print("Sending packet: ");
Serial.println(str_off);
radio.print(str_off);
radio.flush(); //
dump_radio_status_to_serialport(radio.radioState()); // Should report IDLE
delay(1000);
}
void dump_radio_status_to_serialport(uint8_t status)
{
Serial.print("Enrf24 radio transceiver status: ");
switch (status) {
case ENRF24_STATE_NOTPRESENT:
Serial.println("NO TRANSCEIVER PRESENT");
break;
case ENRF24_STATE_DEEPSLEEP:
Serial.println("DEEP SLEEP <1uA power consumption");
break;
case ENRF24_STATE_IDLE:
Serial.println("IDLE module powered up w/ oscillators running");
break;
case ENRF24_STATE_PTX:
Serial.println("Actively Transmitting");
break;
case ENRF24_STATE_PRX:
Serial.println("Receive Mode");
break;
default:
Serial.println("UNKNOWN STATUS CODE");
}
}
Enrf24_RXdemo
/*
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>
Enrf24 radio(P2_0, P2_1, P2_2);
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin(); // Defaults 1Mbps, channel 0, max TX power
dump_radio_status_to_serialport(radio.radioState());
radio.setRXaddress((void*)rxaddr);
radio.enableRX(); // Start listening
}
void loop() {
char inbuf[33];
dump_radio_status_to_serialport(radio.radioState()); // Should show Receive Mode
while (!radio.available(true))
;
if (radio.read(inbuf)) {
Serial.print("Received packet: ");
Serial.println(inbuf);
if (!strcmp(inbuf, str_on))
Serial.println("HIGH");
if (!strcmp(inbuf, str_off))
Serial.println("LOW");
}
}
void dump_radio_status_to_serialport(uint8_t status)
{
Serial.print("Enrf24 radio transceiver status: ");
switch (status) {
case ENRF24_STATE_NOTPRESENT:
Serial.println("NO TRANSCEIVER PRESENT");
break;
case ENRF24_STATE_DEEPSLEEP:
Serial.println("DEEP SLEEP <1uA power consumption");
break;
case ENRF24_STATE_IDLE:
Serial.println("IDLE module powered up w/ oscillators running");
break;
case ENRF24_STATE_PTX:
Serial.println("Actively Transmitting");
break;
case ENRF24_STATE_PRX:
Serial.println("Receive Mode");
break;
default:
Serial.println("UNKNOWN STATUS CODE");
}
}
Natürlich muss man vor bei Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ
die richtigen Pins eingeben.
Jedoch hängt er auch dort:
Sender:
Sending packet: ON/OFF
Enrf24 radio transceiver status: NO TRANSCEIVER PRESENT
Empfänger:
Enrf24 radio transceiver status: NO TRANSCEIVER PRESENT