AVRUC# SERIES COnfiguring MAX7219

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
CLOCKS 

#include <avr32/io.h>
#include "gpio.h"
#include "spi.h"
#include "spi_master.h"
#include "lcd.h"
#include "sysclk.h"
#include "conf_spi.h"
#include "EEPROM.h"
#include "delay.h"
#include "pm.h"

uint8_t status; 






//change this part at different board
#define  CS_Pin      AT25160B_SPI_NPCS0_PIN   //MAX7219    Load-Data Input:    rising edge  pin 12
#define  MOSI_Pin    AT25160B_SPI_MOSI_PIN  //MAX7219    Serial-Data Input:   rising edge  pin 1
#define  CLK_Pin     AT25160B_SPI_SCK_PIN  //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13


void SPI_Write_Byte(unsigned char dataout);

void SPI_Write_Byte(unsigned char dataout)
	{
		unsigned char i;
		unsigned char mask;

		for (i=8; i>0; i--) 
		{
			mask = 1 << (i - 1);		// calculate bitmask
			gpio_clr_gpio_pin(CLK_Pin);  
			if (dataout & mask)		// output one data bit
			gpio_set_gpio_pin(MOSI_Pin)	;	//  "1"
			else				//  or
			gpio_clr_gpio_pin(MOSI_Pin);		//  "0"
			gpio_set_gpio_pin(CLK_Pin);			// bring CLK high
		}
	}

void MAX7219_INIT()
 {
	// Disable Shutdown mode
	gpio_clr_gpio_pin(CS_Pin);              // CS pin is pulled LOW
	SPI_Write_Byte(0x0C);    // Select Shutdown register
	SPI_Write_Byte(0x01);    // Set D0 bit to return to normal operation
	gpio_set_gpio_pin(CS_Pin);              // CS pin is pulled HIGH
	
	// Set BCD decode mode for digits DIG0-DIG3
	gpio_clr_gpio_pin(CS_Pin);         // CS pin is pulled LOW
	SPI_Write_Byte(0x09);    // Select Decode Mode register
	SPI_Write_Byte(0x0F);    // Select BCD mode for digits DIG0-DIG3
	gpio_set_gpio_pin(CS_Pin);            // CS pin is pulled HIGH
	
	// Set display brighness
	gpio_clr_gpio_pin(CS_Pin);            // CS pin is pulled LOW
	SPI_Write_Byte(0x0A);    // Select Intensity register
	SPI_Write_Byte(0x0a);    // Set maximum brightness
	gpio_set_gpio_pin(CS_Pin);       // CS pin is pulled HIGH
	
	// Set display refresh
	gpio_clr_gpio_pin(CS_Pin);            // CS pin is pulled LOW
	SPI_Write_Byte(0x0B);    // Select Scan-Limit register
	SPI_Write_Byte(0x03);    // Select digits DIG0-DIG3
	gpio_set_gpio_pin(CS_Pin);           // CS pin is pulled HIGH
	
	// Enable Display-Test
	gpio_clr_gpio_pin(CS_Pin);             // CS pin is pulled LOW
	SPI_Write_Byte(0x0F);    // Select Display-Test register
	SPI_Write_Byte(0x01);    // Enable Display-Test
	gpio_set_gpio_pin(CS_Pin);    // CS pin is pulled HIGH
	
	delay_ms(1000);
	// Disable Display-Test
	gpio_clr_gpio_pin(CS_Pin);         // CS pin is pulled LOW
	SPI_Write_Byte(0x0F);    // Select Display-Test register
	SPI_Write_Byte(0x00);    // Disable Display-Test
	gpio_set_gpio_pin(CS_Pin);            // CS pin is pulled HIGH
	
}

void WriteEnable(void);

//gpio of spi configuration
 static const gpio_map_t AT25160B_SPI_GPIO_MAP =
 {
	 {AT25160B_SPI_SCK_PIN ,  AT25160B_SPI_SCK_FUNCTION },  // SPI Clock.
	 {AT25160B_SPI_MISO_PIN , AT25160B_SPI_MISO_FUNCTION},  // MISO.
	 {AT25160B_SPI_MOSI_PIN , AT25160B_SPI_MOSI_FUNCTION},  // MOSI.
	 {AT25160B_SPI_NPCS0_PIN , AT25160B_SPI_NPCS0_FUNCTION}   // Chip Select NPCS.
 };
  
 //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.
 };
 
 void WriteEnable(void)
 {
	 spi_selectChip(AS1116_SPI1,0);
	 
	 spi_write(AS1116_SPI1,EEPROM_WREN);// send command
	 
	 spi_unselectChip(AS1116_SPI1,1);
	 
 }
 
 /*spi_options_t options={
	 .reg=AT25160B_SPI_NPCS,
	 .baudrate=SPI_BAUDRATE,
	 .bits=8,
	 .spck_delay=0,
	 .trans_delay=0,
	 .stay_act=1,
	 .spi_mode=0,
	 .modfdis=1
 }; */

 struct spi_device SPI_DEVICE_EXAMPLE = {
	//! Board specific select id
	.id = AT25160B_SPI_NPCS
};

 struct spi_device SPI_DEVICE_EXAMPLE1 = {
	 //! Board specific select id
	 .id = AS1116_SPI1_NPCS
 };


uint8_t output=0;

uint8_t data_send[4]={0x55,0xaa,0xaa,0xcc};
uint16_t data[1]={0x0777};	
	
int main(void)
{
    sysclk_init();
	
	// gpio_enable_module(AT25160B_SPI_GPIO_MAP,sizeof(AT25160B_SPI_GPIO_MAP) / sizeof(AT25160B_SPI_GPIO_MAP[0]));
	gpio_enable_module(AS1116_SPI_GPIO_MAP,sizeof(AS1116_SPI_GPIO_MAP) / sizeof(AS1116_SPI_GPIO_MAP[0]));
	
	initLcd();   
	
	//gpio_enable_gpio_pin(AT25160B_SPI_HOLD);
	//gpio_set_gpio_pin(AT25160B_SPI_HOLD);
	
	
   // spi_master_init(AT25160B_SPI);
	
	spi_master_init(AS1116_SPI1);
	
	//spi_master_setup_device(AT25160B_SPI,&SPI_DEVICE_EXAMPLE, SPI_MODE_0,SPI_BAUDRATE, 0);
	spi_master_setup_device(AS1116_SPI1,&SPI_DEVICE_EXAMPLE1, SPI_MODE_0,SPI_BAUDRATE, 0);
	
	//spi_enable(AT25160B_SPI);
	
	spi_enable(AS1116_SPI1);
	
	
	INTC_init_interrupts();
	Enable_global_interrupt();
	
	delay_ms(100);
    
	//spieepromWriteEnable();
	gpio_enable_gpio_pin(CS_Pin);
	gpio_enable_gpio_pin(MOSI_Pin);
	gpio_enable_gpio_pin(CLK_Pin);

	lcdClear();	
	
	while(1)

		{
			
			
			//delay_ms(3000);
			//spieepromWrite(0x0004,data,1);//write to EEPROM
			 
			    
			//spieepromWriteEnable();
			//spi_unselectChip(AT25160B_SPI,0);
		WriteEnable();
		
		
			//delay_ms(100);
			
					/*	output=spieepromRead(0x0000);//Read from EEPROM
						//delay_ms(100);
						lcdMoveCursor(0,0);
						print_integer(output); //display data on LCD
			
			output=spieepromRead(0x0001);//Read from EEPROM
           //  delay_ms(100);
			lcdMoveCursor(0,4);
			print_integer(output); //display data on LCD
			
			output=spieepromRead(0x0002);//Read from EEPROM
			//delay_ms(100);
			lcdMoveCursor(0,8);
			print_integer(output); //display data on LCD
			
						output=spieepromRead(0x0003);//Read from EEPROM
					//	delay_ms(100);
						lcdMoveCursor(1,0);
						print_integer(output); //display data on LCD
						
									output=spieepromRead(0x0004);//Read from EEPROM
									delay_ms(100);
									lcdMoveCursor(1,4);
									print_integer(output); //display data on LCD
								//	delay_ms(3000);*/
																		
																		
			
			
		}
		
       
}

I m not getting output 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We've got a thousand lines of code and it doesn't work. We have no idea how you've wired it up, no idea of what processor and you have the expectation that we'll be able to divine the problem?

What have you checked so far?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

usually CPOL and CPHA are the things that screw up the SPI slaves  ..... check that