PRELIMINARY
VS1063a Prog. Guide
4
INTERFACING WITH VS1063A USING A MICROCONTROLLER
4.1.1
Example SCI Read / Write Implementation
Using the SpiTransfer() function, here is how to implement register write and read functions:
// VS10XX Operations //
#define VS_WRITE_COMMAND 0x02 /** VS10xx SCI Write Command byte is 0x02 */
#define VS_READ_COMMAND 0x03 /** VS10xx SCI Read Command byte is 0x03 */
/** Put the VS player chip in reset */
#define VsPutInReset(){OUT_SET_LOW(VS_XRESET);}
/** Release the VS player chip from reset */
#define VsReleaseFromReset(){OUT_SET_HIGH(VS_XRESET);}
/** Pull the VS10xx Data Chip Select line Low */
#define VsSelectData(){OUT_SET_LOW(VS_XDCS);}
/** Pull the VS10xx Data Chip Select line High */
#define VsDeselectData(){OUT_SET_HIGH(VS_XDCS);}
void VsWriteRegister(unsigned char reg, unsigned int val){
OUT_SET_LOW(PIN_XCS); // Control Chip Select Low
SpiTransfer(VS_WRITE_COMMAND); // WRITE command
SpiTransfer(reg); // Register number
SpiTransfer((unsigned char)(val >> 8)); // High Byte
SpiTransfer((unsigned char)(val & 0xff)); // Low Byte
OUT_SET_HIGH(PIN_XCS); // Control Chip Select High
}
unsigned int VsReadRegister(unsigned char reg){
unsigned char inHigh;
unsigned char inLow;
OUT_SET_LOW(PIN_XCS); // Control Chip Select Low
SpiTransfer(VS_READ_COMMAND); // READ command
SpiTransfer(reg); // Register number
inHigh = SpiTransfer(0xff); // High Byte
inLow = SpiTransfer(0xff); // Low Byte
OUT_SET_HIGH(PIN_XCS); // Control Chip Select High
return (unsigned short)(inHigh << 8) + inLow;
}
Version: 0.40, 2011-09-02
8