AMC7812B register map and functions (slow functions)
Diff: amc7812b.cpp
- Revision:
- 0:4ad7f160d354
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amc7812b.cpp Thu May 03 19:58:54 2018 +0000 @@ -0,0 +1,89 @@ +/******************************************************* +* +* 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 +} +*/ \ No newline at end of file