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

  1. timer modules
    1. Quadratur Encoder (Version 1.2 - C. Hoyer 12.8.2015)
  2. SPI modules
    1. AD5664 (Version 1.1 - C. Hoyer 23.7.2015)
  3. software modules
    1. Ringbuffer (Version 0.9 - C. Hoyer 18.8.2015)
    2. PID-Regler (Version 1.0 - C. Hoyer 17.9.2015)

SPI/AD5664.cpp

Committer:
ChrisselH
Date:
2016-11-28
Revision:
0:1acdcc576936

File content as of revision 0:1acdcc576936:

#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)                                                                      
           
    }