achar.deepak
Member level 1
Hi all,
I am interfacing AS1116 with AVR32 bit controller through SPI, I need to send LSB first in the code. I am not how to do it. Please help regarding this. I have attached the code with this thread.
Thanks
I am interfacing AS1116 with AVR32 bit controller through SPI, I need to send LSB first in the code. I am not how to do it. Please help regarding this. I have attached the code with this thread.
Thanks
HTML:
/**
* \file
*
* \brief Empty user application template
*
*/
/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* Bare minimum empty user application template
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# "Insert system clock initialization code here" comment
* -# Minimal main function that starts with a call to board_init()
* -# "Insert application code here" comment
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>
void spi_init_module(void);
void test_display(void);
//#define SPI_EXAMPLE (&AVR32_SPI1)
#define AS1116_SPI1 (&AVR32_SPI1)
#define AT25160B_SPI_BAUDRATE 8000000
#define AS1116_SPI1_NPCS 0
#define AS1116_SPI1_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
#define AS1116_SPI1_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
#define AS1116_SPI1_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
#define AS1116_SPI1_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
#define AS1116_SPI1_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
#define AS1116_SPI1_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
#define AS1116_SPI1_NPCS0_PIN AVR32_SPI1_NPCS_0_0_PIN
#define AS1116_SPI1_NPCS0_FUNCTION AVR32_SPI1_NPCS_0_0_FUNCTION
#define AS1116_SHUT 0x0C
#define AS1116_DECODE 0x09
#define AS1116_INTENSITY 0x0A
#define AS1116_SCAN 0x0B
#define AS1116_TESTMODE 0x0F
#define AS1116_FUTURE 0x0E
#define SPITESTMODE 0x00
#define SPISHUT 0x01
#define SPIDECODE 0xFF //00
#define SPIINTENSITY 0xFF //09
#define SPISCAN 0x05
#define SPIFUTURE 0x42
#define DIGIT0 0X01
#define DIGIT1 0X02
#define DIGIT2 0X03
#define DIGIT3 0X04
#define DIGIT4 0X05
#define DIGIT5 0X06
struct spi_device spi_device_conf = {
.id = AS1116_SPI1_NPCS // IOPORT_CREATE_PIN(PORTD, 1)
};
uint8_t data[]={0x02};
uint8_t data1[]={0xFF};
void spi_init_module(void)
{
//gpio of spi configuration
static const gpio_map_t AS1116_SPI_GPIO_MAP =
{
{AS1116_SPI1_SCK_PIN , AS1116_SPI1_SCK_FUNCTION}, // SPI Clock.
{AS1116_SPI1_MISO_PIN ,AS1116_SPI1_MISO_FUNCTION }, // MISO.
{AS1116_SPI1_MOSI_PIN , AS1116_SPI1_MOSI_FUNCTION}, // MOSI.
{AS1116_SPI1_NPCS0_PIN , AS1116_SPI1_NPCS0_FUNCTION} // Chip Select NPCS.
};
gpio_enable_module(AS1116_SPI_GPIO_MAP,sizeof(AS1116_SPI_GPIO_MAP) / sizeof(AS1116_SPI_GPIO_MAP[0]));
//Init SPI module as master
spi_master_init( AS1116_SPI1 );
//Setup parameters for the slave device
spi_master_setup_device(AS1116_SPI1 , &spi_device_conf,SPI_MODE_0 , AT25160B_SPI_BAUDRATE , 0);
//Allow the module to transfer data
spi_enable( AS1116_SPI1 );
}
void test_display(void)
{
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT0,1);
spi_write_packet(AS1116_SPI1,0x01,1);// send command
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT1,1);
spi_write_packet(AS1116_SPI1,0x02,1);// send command
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT2,1);
spi_write_packet(AS1116_SPI1,0X03,1);// send command
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT3,1);
spi_write_packet(AS1116_SPI1,0X04,1);// send command
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT4,1);
spi_write_packet(AS1116_SPI1,0X05,1);// send command
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,DIGIT5,1);
spi_write_packet(AS1116_SPI1,0X06,1);// send command
spi_unselectChip(AS1116_SPI1,1);
}
int main (void)
{
// Insert system clock initialization code here (sysclk_init()).
board_init();
//Buffer to send data to SPI slave
uint8_t txdata[1]={0x0C}; //Buffer to receive data from SPI slave
uint8_t rxdata[1]={0x01};
spi_init_module();
while(1)
{
/*// Select the slave device with chip select
spi_select_device(AS1116_SPI1 ,&spi_device_conf);
// Send the data to slave
spi_write_packet(AS1116_SPI1 , txdata, 1);
// Read data from slave
spi_read_packet(AS1116_SPI1, rxdata,1);
// De select the slave
spi_deselect_device(AS1116_SPI1 ,&spi_device_conf);*/
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_SHUT,1);// send command
spi_write_packet(AS1116_SPI1,SPISHUT,1);
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_INTENSITY,1);// send command
spi_write_packet(AS1116_SPI1,SPIINTENSITY,1);
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_SCAN,1);// send command
spi_write_packet(AS1116_SPI1,SPISCAN,1 );
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_DECODE,1);// send command
spi_write_packet(AS1116_SPI1,SPIDECODE,1);
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_TESTMODE,1);// send command
spi_write_packet(AS1116_SPI1,SPITESTMODE,1);
spi_unselectChip(AS1116_SPI1,1);
spi_selectChip(AS1116_SPI1,0);
spi_write_packet(AS1116_SPI1,AS1116_FUTURE,1);// send command
spi_write_packet(AS1116_SPI1,SPIFUTURE,1);
spi_unselectChip(AS1116_SPI1,1);
test_display();
}
// Insert application code here, after the board has been initialized.
}