Jump to content
Sign in to follow this  
Prabhat

Help with interfacing MAX7456 OSD with ATMega32

Recommended Posts

Hello there.. I m trying to interface MAX7456 OSD with Atmel ATMega32. But I m not getting any characters on screen. Its coming grey (as expected) background but nothing else. I have programmed using CodeVision AVR. The code is given below.

#include <mega32.h>
#include <spi.h>
#include <delay.h>

#define SPI_CS PORTB.4

void main(void)
{
unsigned char ad;/*address*/
unsigned char da;/*DATA*/
unsigned char d; /*Discard echo*/
unsigned char t; /*To modify 4th bit of OSDBL*/

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=0 State0=0
PORTA=0x00;
DDRA=0x03;

// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xB0;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 4000.000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00;

SPI_CS=1;
delay_ms(100);

ad=0x00;
da=0x7A; //Pal and internal sync,enable display and software reset
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x00;
da=0x78; //Pal and internal sync and enable display
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x01; //VM1
da=0xC7;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x04; //DMM
da=0x20;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x05; //DMAH
da=0x00;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x06; //DMAL
da=0x00;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x07; //DMAL
da=0x01; //To display 1
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x05; //DMAH
da=0x00;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x06; //DMAL
da=0x01;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x07; //DMAL
da=0x02; //To display 2
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x05; //DMAH
da=0x00;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x06; //DMAL
da=0x02;
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0x07; //DMAL
da=0x03; //To display 3
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

ad=0xEC; //OSDBL Read
da=0x00; //Garbage
SPI_CS=0;
d=spi(ad);
d=spi(da); // now d will contain the read value
SPI_CS=1;
delay_ms(100);

t=(unsigned int) d;
t=t & 0xEF; // Modify 4th bit to 0
da=(unsigned char) t;
ad=0x6C; //OSDBL Write
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);

while(1)
;

}[/codebox]

As given above I m using standard function spi.h. According to codevision AVR datasheet , the spi function is unsigned char spi(unsigned char data); This function sends a byte data, simultaneously receiving a byte. Hence I m using 'd' to discard off echo I get and to read the contents of OSDBL. Why isn't characters being displayed ?? The program is supposed to display 123. Is there anything wrong with the code ?? Please assist me as soon as possible.. I have uploaded the MAX7456 part of the circuit. Thank you. :)

Prabhat

post-5508-1243869864_thumb.jpg

Share this post


Link to post
Share on other sites

There's a lot of code there; I don't have enough free time to comb through it. However, I see that the wrong SPI data width was chosen:

{Your code is for 8-bit data, but the MAX has been set to 16-bit.}

ad=0x00;
ad=0x04; //DMM
da=0x20; // THIS SHOULD BE 0x40
SPI_CS=0;
d=spi(ad);
d=spi(da);
SPI_CS=1;
delay_ms(100);[/codebox]

Also, I don't believe you need to do the dummy read (I don't do it). The delay is excessively long too. So, keep that in mind if you need to speed up your code.

Lastly, if your 2-channel oscope is not at the programming workstation to help you debug the code, then I would encourage you to use it. Set it up on the SPI buss. The scope will tell you everything you need to know to get this to run. Honestly, without the scope at your side you will be flying blind while writing the embedded code.

Share this post


Link to post
Share on other sites

Thank you.. Now I m getting outout, the font size is bigger though for a 21" tv. I wanted to ask this. If I construct the circuit diagram part of the MAX7456 as in datasheet except taking care of /HSYNC, LOS (output) and /VSYNC, and I apply an input CVBS through a camera (which has capability of connecting to tv), will I get a background picture from camera without changing any settings of the above program?? If not, what settings should I change ?? Please assist. Thank you.

Edited by Prabhat

Share this post


Link to post
Share on other sites

To use the composite video input you will need to change VM0 (register 0x00) to use auto or external sync. All these details are in the data sheet, so it is best to consult with it.

Share this post


Link to post
Share on other sites

The chip is extremly well described in datasheet - in my unit first letters I was able to display literaly within 3 hours . Within two evenings all functions for display anything useful was ready .

I recommend to read datasheet - there are also explanations for some tips .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×