Libs for using Nucleo STM32F411 periphery
Introduction
Descruption: This lib uses the hardware peripherie from STM32F411 under serveral conditions. So you can use an quadraturencoder with different timers.
Requirement: Only tested with the nucleo F411. Include the mbed lib! Interfacing details are explained in the documentary of each class.
Overview
- timer modules
- Quadratur Encoder (Version 1.2 - C. Hoyer 12.8.2015)
- SPI modules
- AD5664 (Version 1.1 - C. Hoyer 23.7.2015)
- software modules
- Ringbuffer (Version 0.9 - C. Hoyer 18.8.2015)
- PID-Regler (Version 1.0 - C. Hoyer 17.9.2015)
Diff: SPI/AD5664.cpp
- Revision:
- 0:1acdcc576936
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SPI/AD5664.cpp Mon Nov 28 17:27:43 2016 +0000 @@ -0,0 +1,137 @@ +#include "mbed.h" +#include "AD5664.h" + +//==================================================================================================================================== +// Grundlagen, DAC Schreiben und Initialisieren +//==================================================================================================================================== + +AD5664::AD5664(SPI _spi, PinName _daccs): spi(_spi), daccs(_daccs) +{ + sendDAC(0x2F, 0x00, 0x00); //Software Reset, alle Ausgänge auf 0 + } + + +void AD5664::sendDAC(int instruction = 0x00, int data1 = 0x00, int data2 = 0x00) +{ + daccs = 0; // Select Device + + spi.write(instruction); // Schreibt entsprechend die Anweisung und die Adresse + spi.write(data1); // Schreibt den ersten Byte an Daten + spi.write(data2); // Schreibt den zweiten Byte an Daten + + daccs = 1; // Deselect + } + +//==================================================================================================================================== +// Setter-Funktionen +//==================================================================================================================================== + +void AD5664::SelectCS() +{ daccs = 0; // Select Device + } + +void AD5664::DeselectCS() +{ daccs = 1; // Deselect + } + +void AD5664::writeDAC(char channel, int value) +{ + int choch = 0x00; //Temporäre Variable um die Instructions zu übernehmen + + switch(channel){ + case 'A': // DAC A + choch = 0x18; + break; + + case 'B': // DAC B + choch = 0x19; + break; + + case 'C': // DAC C + choch = 0x1A; + break; + + case 'D': // DAC D + choch = 0x1B; + break; + + case 'F': // Alle Dacs + choch = 0x1F; + break; + + default: + choch = 0x1F; // Alle Dacs + } + + sendDAC(choch, *((uint8_t*)&(value)+1), *((uint8_t*)&(value)+0)); //Schreibe via SPI: Anweisung mit Adresse, oberes Byte, unteres Byte) + + } + + + +void AD5664::loadDAC(char channel, int value) +{ + int choch = 0x00; //Temporäre Variable um die Instructions zu übernehmen + + switch(channel){ + case 'A': // DAC A + choch = 0x00; + break; + + case 'B': // DAC B + choch = 0x01; + break; + + case 'C': // DAC C + choch = 0x02; + break; + + case 'D': // DAC D + choch = 0x03; + break; + + case 'F': // Alle Dacs + choch = 0x07; + break; + + default: + choch = 0x07; // Alle Dacs + } + + sendDAC(choch, *((uint8_t*)&(value)+1), *((uint8_t*)&(value)+0)); //Schreibe via SPI: Anweisung mit Adresse, oberes Byte, unteres Byte) + + } + + +void AD5664::updateDAC(char channel) +{ + int choch = 0x00; //Temporäre Variable um die Instructions zu übernehmen + + switch(channel){ + case 'A': // DAC A + choch = 0x08; + break; + + case 'B': // DAC B + choch = 0x09; + break; + + case 'C': // DAC C + choch = 0x0A; + break; + + case 'D': // DAC D + choch = 0x0B; + break; + + case 'F': // Alle Dacs + choch = 0x0F; + break; + + default: + choch = 0x0F; // Alle Dacs + } + + sendDAC(choch, 0x00 , 0x00); //Schreibe via SPI: Anweisung mit Adresse, oberes Byte, unteres Byte) + + }