Skip to content

Instantly share code, notes, and snippets.

@ti-nspire
Last active January 19, 2020 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ti-nspire/8ae3dc0f8f339cd8b14025d4edc90b98 to your computer and use it in GitHub Desktop.
Save ti-nspire/8ae3dc0f8f339cd8b14025d4edc90b98 to your computer and use it in GitHub Desktop.
AD8402_Example_for_ATmega328P
#include <avr/io.h>
#include <util/delay.h>
extern "C" {
#include "USART.h"
}
#include "mySPIv2.h"
#include "AD8402.h"
int main(){
initUSART();
AD8402 pot('B', 2); // PB2を!SS端子としてSPIスレーブを実体化する。PB3~PB5は!SS端子に指定してはならない。
mySPI.enable(128, 0, 'M'); // (システムクロックの分周比128, モード0, MSBファースト)でAVRのSPIモジュールを開始する。
uint8_t ch;
uint8_t pos;
// 電源投入時のワイパーの位置は不定である。ここでは中間点にしておく。
pot.setChPos(1, 0x80);
pot.setChPos(2, 0x80);
while(1){
printString("Enter a channel, 1 or 2: ");
ch = getNumber();
printString("Enter a position of the wiper, 0-255: ");
pos = getNumber();
pot.setChPos(ch, pos);
printString("!SS pin : P"); transmitByte(pot.getPort()); printNibble(pot.getPin()); printString("\n");
printString("Ch1 Position: "); printByte(pot.getPosOfCh(1)); printString("\n");
printString("Ch2 Position: "); printByte(pot.getPosOfCh(2)); printString("\n\n");
}
//mySPI.disable();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment