Mauricio Donatti / AMC7812B
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers amc7812b.cpp Source File

amc7812b.cpp

00001 /*******************************************************
00002 *
00003 * Texas Instruments AMC7812B library
00004 *
00005 * Author: Mauricio Donatti
00006 * E-mail: mauricio.donatti@lnls.br
00007 *
00008 * March 2018
00009 *
00010 *******************************************************/
00011 
00012 #include "amc7812b.h"
00013 
00014 //OLD FUNCTIONS
00015 //They are not used anymore - New functions inside main.cpp are more efficient
00016 
00017 /*
00018 void AMC_write(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
00019 {
00020         cs = 0; // Select the device by seting chip select low
00021         spi.write((reg<<4)|((data[1]&0xF0)>>4));
00022         spi.write((data[0])|((data[1]&0xF)<<8));
00023         cs = 1; // Deselect the device by seting chip select low    
00024 }
00025 
00026 void AMC_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
00027 {
00028         uint16_t tmp;
00029         cs = 0; // Select the device by seting chip select low
00030         //spi.write(reg|0x80);
00031         //spi.write(0x00);
00032         //spi.write(0x00);
00033         spi.write((reg|0x80)<<4);
00034         spi.write(0x000);
00035         cs = 1; // Deselect the device by seting chip select low
00036         cs = 0; // Select the device by seting chip select low
00037         tmp = spi.write((reg|0x80)<<4);
00038         data[1] = (tmp&0xF)<<4;
00039         tmp = spi.write(0x000);
00040         data[1] = data[1]|((tmp&0xF00)>>8);
00041         data[0] = tmp&0xFF;
00042         //data[1] = spi.write(0x000);
00043         //data[0] = spi.write(0x00);
00044         cs = 1; // Deselect the device by seting chip select low       
00045 }
00046 
00047 //read_fast saves the data of the previous read_fast call 
00048 void AMC_read_fast(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
00049 {
00050         uint16_t tmp;
00051 
00052         cs = 0; // Select the device by seting chip select low
00053         tmp = spi.write((reg|0x80)<<4);
00054         data[1] = (tmp&0xF)<<4;
00055         tmp = spi.write(0x000);
00056         data[1] = data[1]|((tmp&0xF00)>>8);
00057         data[0] = tmp&0xFF;
00058         //spi.write(reg|0x80);
00059         //data[1] = spi.write(0x00);
00060         //data[0] = spi.write(0x00);
00061         cs = 1; // Deselect the device by seting chip select low    
00062 }
00063 
00064 
00065 //read_fast saves the data of the previous read_fast call 
00066 void AMC_my_read(SPI spi, DigitalOut cs, uint8_t reg,uint8_t* data)
00067 {
00068         uint16_t tmp;
00069         cs = 0; // Select the device by seting chip select low
00070         //spi.write(reg|0x80);
00071         //data[1] = spi.write(0x00);
00072         //data[0] = spi.write(0x00);
00073         
00074         //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
00075         LPC_SSP1->DR = (reg|0x80)<<4;  // write to FIFO data register
00076         while( !(LPC_SSP1->SR & 4));
00077         tmp = LPC_SSP1->DR;  // hopefully the compiler won't optimize this
00078         data[1] = (tmp&0xF)<<4;
00079         //while (!(LPC_SSP1->SR & 2)); //if TNF-Bit = 0 (FIFO full); TNF-Bit is Bit 1 in SSPxSR
00080         LPC_SSP1->DR = 0x000;  // write to FIFO data register
00081         while( !(LPC_SSP1->SR & 4));  
00082         //while ( (LPC_SSP1->SR & (SSPSR_BSY|SSPSR_RNE)) != SSPSR_RNE ); 
00083         tmp = LPC_SSP1->DR;  // hopefully the compiler won't optimize this
00084         data[1] = data[1]|((tmp&0xF00)>>8);
00085         data[0] = tmp&0xFF;
00086                 
00087         cs = 1; // Deselect the device by seting chip select low    
00088 }
00089 */