AMC7812B register map and functions (slow functions)

amc7812b.cpp

Committer:
mmdonatti
Date:
2018-05-03
Revision:
0:4ad7f160d354

File content as of revision 0:4ad7f160d354:

/*******************************************************
*
* Texas Instruments AMC7812B library
*
* Author: Mauricio Donatti
* E-mail: mauricio.donatti@lnls.br
*
* March 2018
*
*******************************************************/

#include "amc7812b.h"

//OLD FUNCTIONS
//They are not used anymore - New functions inside main.cpp are more efficient

/*
void AMC_write(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
{
        cs = 0; // Select the device by seting chip select low
        spi.write((reg<<4)|((data[1]&0xF0)>>4));
        spi.write((data[0])|((data[1]&0xF)<<8));
        cs = 1; // Deselect the device by seting chip select low    
}

void AMC_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
{
        uint16_t tmp;
        cs = 0; // Select the device by seting chip select low
        //spi.write(reg|0x80);
        //spi.write(0x00);
        //spi.write(0x00);
        spi.write((reg|0x80)<<4);
        spi.write(0x000);
        cs = 1; // Deselect the device by seting chip select low
        cs = 0; // Select the device by seting chip select low
        tmp = spi.write((reg|0x80)<<4);
        data[1] = (tmp&0xF)<<4;
        tmp = spi.write(0x000);
        data[1] = data[1]|((tmp&0xF00)>>8);
        data[0] = tmp&0xFF;
        //data[1] = spi.write(0x000);
        //data[0] = spi.write(0x00);
        cs = 1; // Deselect the device by seting chip select low       
}

//read_fast saves the data of the previous read_fast call 
void AMC_read_fast(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
{
        uint16_t tmp;

        cs = 0; // Select the device by seting chip select low
        tmp = spi.write((reg|0x80)<<4);
        data[1] = (tmp&0xF)<<4;
        tmp = spi.write(0x000);
        data[1] = data[1]|((tmp&0xF00)>>8);
        data[0] = tmp&0xFF;
        //spi.write(reg|0x80);
        //data[1] = spi.write(0x00);
        //data[0] = spi.write(0x00);
        cs = 1; // Deselect the device by seting chip select low    
}


//read_fast saves the data of the previous read_fast call 
void AMC_my_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
{
        uint16_t tmp;
        cs = 0; // Select the device by seting chip select low
        //spi.write(reg|0x80);
        //data[1] = spi.write(0x00);
        //data[0] = spi.write(0x00);
        
        //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
        LPC_SSP1->DR = (reg|0x80)<<4;  // write to FIFO data register
        while( !(LPC_SSP1->SR & 4));
        tmp = LPC_SSP1->DR;  // hopefully the compiler won't optimize this
        data[1] = (tmp&0xF)<<4;
        //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
        LPC_SSP1->DR = 0x000;  // write to FIFO data register
        while( !(LPC_SSP1->SR & 4));  
        //while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); 
        tmp = LPC_SSP1->DR;  // hopefully the compiler won't optimize this
        data[1] = data[1]|((tmp&0xF00)>>8);
        data[0] = tmp&0xFF;
                
        cs = 1; // Deselect the device by seting chip select low    
}
*/