AMC7812B register map and functions (slow functions)

Committer:
mmdonatti
Date:
Thu May 03 19:58:54 2018 +0000
Revision:
0:4ad7f160d354
AMC7812B library - registers and slow functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mmdonatti 0:4ad7f160d354 1 /*******************************************************
mmdonatti 0:4ad7f160d354 2 *
mmdonatti 0:4ad7f160d354 3 * Texas Instruments AMC7812B library
mmdonatti 0:4ad7f160d354 4 *
mmdonatti 0:4ad7f160d354 5 * Author: Mauricio Donatti
mmdonatti 0:4ad7f160d354 6 * E-mail: mauricio.donatti@lnls.br
mmdonatti 0:4ad7f160d354 7 *
mmdonatti 0:4ad7f160d354 8 * March 2018
mmdonatti 0:4ad7f160d354 9 *
mmdonatti 0:4ad7f160d354 10 *******************************************************/
mmdonatti 0:4ad7f160d354 11
mmdonatti 0:4ad7f160d354 12 #include "amc7812b.h"
mmdonatti 0:4ad7f160d354 13
mmdonatti 0:4ad7f160d354 14 //OLD FUNCTIONS
mmdonatti 0:4ad7f160d354 15 //They are not used anymore - New functions inside main.cpp are more efficient
mmdonatti 0:4ad7f160d354 16
mmdonatti 0:4ad7f160d354 17 /*
mmdonatti 0:4ad7f160d354 18 void AMC_write(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
mmdonatti 0:4ad7f160d354 19 {
mmdonatti 0:4ad7f160d354 20 cs = 0; // Select the device by seting chip select low
mmdonatti 0:4ad7f160d354 21 spi.write((reg<<4)|((data[1]&0xF0)>>4));
mmdonatti 0:4ad7f160d354 22 spi.write((data[0])|((data[1]&0xF)<<8));
mmdonatti 0:4ad7f160d354 23 cs = 1; // Deselect the device by seting chip select low
mmdonatti 0:4ad7f160d354 24 }
mmdonatti 0:4ad7f160d354 25
mmdonatti 0:4ad7f160d354 26 void AMC_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
mmdonatti 0:4ad7f160d354 27 {
mmdonatti 0:4ad7f160d354 28 uint16_t tmp;
mmdonatti 0:4ad7f160d354 29 cs = 0; // Select the device by seting chip select low
mmdonatti 0:4ad7f160d354 30 //spi.write(reg|0x80);
mmdonatti 0:4ad7f160d354 31 //spi.write(0x00);
mmdonatti 0:4ad7f160d354 32 //spi.write(0x00);
mmdonatti 0:4ad7f160d354 33 spi.write((reg|0x80)<<4);
mmdonatti 0:4ad7f160d354 34 spi.write(0x000);
mmdonatti 0:4ad7f160d354 35 cs = 1; // Deselect the device by seting chip select low
mmdonatti 0:4ad7f160d354 36 cs = 0; // Select the device by seting chip select low
mmdonatti 0:4ad7f160d354 37 tmp = spi.write((reg|0x80)<<4);
mmdonatti 0:4ad7f160d354 38 data[1] = (tmp&0xF)<<4;
mmdonatti 0:4ad7f160d354 39 tmp = spi.write(0x000);
mmdonatti 0:4ad7f160d354 40 data[1] = data[1]|((tmp&0xF00)>>8);
mmdonatti 0:4ad7f160d354 41 data[0] = tmp&0xFF;
mmdonatti 0:4ad7f160d354 42 //data[1] = spi.write(0x000);
mmdonatti 0:4ad7f160d354 43 //data[0] = spi.write(0x00);
mmdonatti 0:4ad7f160d354 44 cs = 1; // Deselect the device by seting chip select low
mmdonatti 0:4ad7f160d354 45 }
mmdonatti 0:4ad7f160d354 46
mmdonatti 0:4ad7f160d354 47 //read_fast saves the data of the previous read_fast call
mmdonatti 0:4ad7f160d354 48 void AMC_read_fast(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
mmdonatti 0:4ad7f160d354 49 {
mmdonatti 0:4ad7f160d354 50 uint16_t tmp;
mmdonatti 0:4ad7f160d354 51
mmdonatti 0:4ad7f160d354 52 cs = 0; // Select the device by seting chip select low
mmdonatti 0:4ad7f160d354 53 tmp = spi.write((reg|0x80)<<4);
mmdonatti 0:4ad7f160d354 54 data[1] = (tmp&0xF)<<4;
mmdonatti 0:4ad7f160d354 55 tmp = spi.write(0x000);
mmdonatti 0:4ad7f160d354 56 data[1] = data[1]|((tmp&0xF00)>>8);
mmdonatti 0:4ad7f160d354 57 data[0] = tmp&0xFF;
mmdonatti 0:4ad7f160d354 58 //spi.write(reg|0x80);
mmdonatti 0:4ad7f160d354 59 //data[1] = spi.write(0x00);
mmdonatti 0:4ad7f160d354 60 //data[0] = spi.write(0x00);
mmdonatti 0:4ad7f160d354 61 cs = 1; // Deselect the device by seting chip select low
mmdonatti 0:4ad7f160d354 62 }
mmdonatti 0:4ad7f160d354 63
mmdonatti 0:4ad7f160d354 64
mmdonatti 0:4ad7f160d354 65 //read_fast saves the data of the previous read_fast call
mmdonatti 0:4ad7f160d354 66 void AMC_my_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
mmdonatti 0:4ad7f160d354 67 {
mmdonatti 0:4ad7f160d354 68 uint16_t tmp;
mmdonatti 0:4ad7f160d354 69 cs = 0; // Select the device by seting chip select low
mmdonatti 0:4ad7f160d354 70 //spi.write(reg|0x80);
mmdonatti 0:4ad7f160d354 71 //data[1] = spi.write(0x00);
mmdonatti 0:4ad7f160d354 72 //data[0] = spi.write(0x00);
mmdonatti 0:4ad7f160d354 73
mmdonatti 0:4ad7f160d354 74 //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
mmdonatti 0:4ad7f160d354 75 LPC_SSP1->DR = (reg|0x80)<<4; // write to FIFO data register
mmdonatti 0:4ad7f160d354 76 while( !(LPC_SSP1->SR & 4));
mmdonatti 0:4ad7f160d354 77 tmp = LPC_SSP1->DR; // hopefully the compiler won't optimize this
mmdonatti 0:4ad7f160d354 78 data[1] = (tmp&0xF)<<4;
mmdonatti 0:4ad7f160d354 79 //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
mmdonatti 0:4ad7f160d354 80 LPC_SSP1->DR = 0x000; // write to FIFO data register
mmdonatti 0:4ad7f160d354 81 while( !(LPC_SSP1->SR & 4));
mmdonatti 0:4ad7f160d354 82 //while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE );
mmdonatti 0:4ad7f160d354 83 tmp = LPC_SSP1->DR; // hopefully the compiler won't optimize this
mmdonatti 0:4ad7f160d354 84 data[1] = data[1]|((tmp&0xF00)>>8);
mmdonatti 0:4ad7f160d354 85 data[0] = tmp&0xFF;
mmdonatti 0:4ad7f160d354 86
mmdonatti 0:4ad7f160d354 87 cs = 1; // Deselect the device by seting chip select low
mmdonatti 0:4ad7f160d354 88 }
mmdonatti 0:4ad7f160d354 89 */