Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Control a MAX7219 by Oshonsoft?

Status
Not open for further replies.

revave

Member
Hello,

Is it possible to control a MAX7219 LED-driver by Oshonsoft code? The serial communication to a MAX7219 is not 100% compatible to SPI.
The MAX7219 is communicating by folowing ports:
-DIN
-CLK

CS will not be used at the MAX7219, so for the selection of the chip LOAD must be high i think?
Is it true that i don't have to use slave adresses? I want to use two drivers and each driver has it's own function.
With normal SPI you'll give a slaveadress, but is it correct that i only have to make the LOAD-input high at the driver i want to write to?


Does anyone have a working example for this kind of communication?
(I know that the MAX7221 if fully compatible to SPI, but i bought by mismatch 10pcs of MAX7219 chips and they are not cheap)

Thank you!

Reijnko Vast
 
Last edited:
hi,

It should be possible to create a 16 bit serial Data WORD string and Clock it out, using Oshonsoft Basic.

The upper 8 bits of the WORD would be XXXX[addr] and the lower 8 bits the displayed data for that DIGIT.

What is you clock speed and PIC type.??

E
 
Hello,

The clockspeed is 16 Mhz and the chip is a 16f628a. Maybe this chip will be replaced by a 18f2550.

Reijnko
 
Hello,

The clockspeed is 16 Mhz and the chip is a 16f628a. Maybe this chip will be replaced by a 18f2550.

Reijnko

hi,
I would consider assigning a 'labelled' 16 bit WORD for each LED Digit [8 WORD's]

Preload the upper BYTE of each WORD with the xxxx and the LED's address

Load as required the lower BYTE of the WORD with the required Digit to be displayed.

You could then either cycle thru all the digit WORD's or select a Digit label.
Then the serial WORD transfer to the 7219 would be a Data/Clock sub routine.

Do you have Code you could post so that we can check it.?

E.
 
Take a look at the microchip mcp4921 DAC.. This uses a 16 bit transfer I write to this in Oshonsoft.

Code:
Define SPI_CS_REG = PORTC
Define SPI_CS_BIT = 0
Define SPI_SCK_REG = PORTC
Define SPI_SCK_BIT = 3
Define SPI_SDI_REG = PORTC
Define SPI_SDI_BIT = 5
Define SPI_SDO_REG = PORTC
Define SPI_SDO_BIT = 4
SPIPrepare



Code:
Proc sendspi(x As Word, t As Byte)
	If x > 4095 Then x = 4095
	x = x + 0x3000

	PORTD = t
	SPISend x.HB
	SPISend x.LB
	PORTD = 0xff
End Proc
 
hi,
I would consider assigning a 'labelled' 16 bit WORD for each LED Digit [8 WORD's]

Preload the upper BYTE of each WORD with the xxxx and the LED's address

Load as required the lower BYTE of the WORD with the required Digit to be displayed.

You could then either cycle thru all the digit WORD's or select a Digit label.
Then the serial WORD transfer to the 7219 would be a Data/Clock sub routine.

Do you have Code you could post so that we can check it.?

E.

Hello E,

I do not have any code yet. First i want to do some research for the communication and after i understand the logic about the communication i'll write the code for the PIC's.

Is it correct that CLK must be high and then folwwed by the 16 bit WORD at the DATA-line. Then make CLK low and repeat this routine for the following words? LOAD is then used for the chip i want to write to?

Reijnko
 
Take a look at the microchip mcp4921 DAC.. This uses a 16 bit transfer I write to this in Oshonsoft.

Code:
Define SPI_CS_REG = PORTC
Define SPI_CS_BIT = 0
Define SPI_SCK_REG = PORTC
Define SPI_SCK_BIT = 3
Define SPI_SDI_REG = PORTC
Define SPI_SDI_BIT = 5
Define SPI_SDO_REG = PORTC
Define SPI_SDO_BIT = 4
SPIPrepare



Code:
Proc sendspi(x As Word, t As Byte)
	If x > 4095 Then x = 4095
	x = x + 0x3000

	PORTD = t
	SPISend x.HB
	SPISend x.LB
	PORTD = 0xff
End Proc

Hello Ian,

This is a normal SPI routine. Does that mean that the SDO won't be used for the 7219?
CS is then used for LOAD at the 7219?

That means then that the 7219 can be controlled by an standard SPI routine ithout using the SDO-port?


Reijnko
 
hi,
As Ian points out the Oshonsoft 'high or low' SPI commands can be used to transfer serial data.

There are examples in the Oshonsoft Basic manual documentation.

I expect that you will selecting either of the two individual 7219 by a PIC pin.?
E
 
Hi Eric,

Yes. I understand the normal spi statements in Oshonsoft. Still wondering where SDO portc.4 is used for. Can i ignore the sdo connection? Because i only write to the 7219.

You are right. Each chip uses an io port for the load/cs bit.

So, as a summary: i can use the normal SPI instructionset in Oshonsoft and can ignore the SDO port?
 
hi,
Just use the SPI send commands [ initialise the SPI pins first]
I use this code for writing to an EEPROM.



Code:
For addr = 0 To 10 
data = 200 - addr 
SPICSOn 
SPISend 0x06 
SPICSOff 
SPICSOn 
SPISend 0x02 
SPISend addr 
SPISend data 
SPICSOff 
Lcdcmdout LcdClear 
Lcdout "Write To EEPROM" 
Lcdcmdout LcdLine2Home 
Lcdout "(", #addr, ") = ", #data 
WaitMs 500 
Next addr

Added init style code: Change the pins to suit your application

Code:
Here is one example for using 25C040 SPI eeprom: 
AllDigital 
Define SPI_CS_REG = PORTC 
Define SPI_CS_BIT = 0 
Define SPI_SCK_REG = PORTC 
Define SPI_SCK_BIT = 3 
Define SPI_SDI_REG = PORTC 
Define SPI_SDI_BIT = 5 
Define SPI_SDO_REG = PORTC 
Define SPI_SDO_BIT = 4 
SPIPrepare
 
Hi Eric,

I saw this code in an example. You write as first 0x06 followed by 0x02.
The last one is the slaveadress i think. What is the reason of 0x06?
At init the 7219 doesn't have an adress....

Reijnko.
 
Hi Eric,

Yes. I understand the normal spi statements in Oshonsoft. Still wondering where SDO portc.4 is used for. Can i ignore the sdo connection? Because i only write to the 7219.

You are right. Each chip uses an io port for the load/cs bit.

So, as a summary: i can use the normal SPI instructionset in Oshonsoft and can ignore the SDO port?

Yep.... I do! Its a continuous buffer link anyway... The thing about Oshonsoft is its a software implementation anyway so the other pin isn't used anyway.
 
Hi Eric,

I saw this code in an example. You write as first 0x06 followed by 0x02.
The last one is the slaveadress i think. What is the reason of 0x06?
At init the 7219 doesn't have an adress....

Reijnko.

hi,
The addresses for the 7219 are its Digit location address.

The 'sample' code I posted is for an EEPROM which requires the 0x02 and 0x06 codes to command the EEPROM to perform a certain internal action.

The 7219 will required this type of internal Command instruction, they are listed in the d/sheet.

Check the d/s for the required code and use SPISend.

E
 

Attachments

  • AAesp02.gif
    AAesp02.gif
    19.3 KB · Views: 459
Hello Eric and Ian,

Thank you both for your quick reply's.
Tonight i want to do some experiments with softwarecode.
If i'll get it work then i will post the softwarecode here. Then other people can use it too.

Best regards,
Reijnko
 
Hello Eric and Ian,

Thank you both for your quick reply's.
Tonight i want to do some experiments with softwarecode.
If i'll get it work then i will post the softwarecode here. Then other people can use it too.

Best regards,
Reijnko

hi,
Use the Oscilloscope module in the Tools section of Oshonsoft to check the SPI output pin.

E
 
Hello,

Here's a piece of testcode. It doesn't work yet. I'm still investigating to a solution, but reply's at the code are very welcome..

Code:
'PIC 16F628A, with 16Mhz crystal and pull ups (10k) at SDI and CLK
'This program has to energize led 0,1 and 7 of row 2 at a 8x8 ledmatrix (rownumbers numbered 1..8)

Define CONF_WORD = 0x3f42

AllDigital
Define CLOCK_FREQUENCY = 16

Define SPI_CS_REG = PORTB
Define SPI_CS_BIT = 1
Define SPI_SCK_REG = PORTB  'with pull up (10k)
Define SPI_SCK_BIT = 2
Define SPI_SDI_REG = PORTB  'with pull up (10k)
Define SPI_SDI_BIT = 0
Define SPI_SDO_REG = PORTB
Define SPI_SDO_BIT = 3
SPIPrepare

'****************************************
'Init MAX7219
SPICSOn
SPISend 12  'Registeradress shutdown
SPISend 1  'value written To registry
SPICSOff
WaitMs 10

SPICSOn
SPISend 9  'Registeradress decode mode
SPISend 0  'value written to registry
SPICSOff
WaitMs 10

SPICSOn
SPISend 11  'Registeradress scanlimit
SPISend 7  'value written to registry
SPICSOff
WaitMs 10

SPICSOn
SPISend 10  'Registeradress intensity
SPISend 1  'value written to registry
SPICSOff
WaitMs 10

SPICSOn
SPISend 15  'Registeradress testmode/ normal mode
SPISend 0  'value written to registry
SPICSOff
WaitMs 10
'End of init
'****************************************

main:
SPICSOn
SPISend 0x02  'Registeradress (digit 1)
SPISend 131  'bit 0, 1 and 7 for test
SPICSOff
WaitMs 10
Goto main
'End of mainprogram
'****************************************

Best regards,
Reijnko
 
Last edited:
hi,
Looks OK to me.:D

Three images of the scope,, image3 is the 'main' loop


Eric
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    10.7 KB · Views: 422
  • AAesp02.gif
    AAesp02.gif
    10.4 KB · Views: 448
  • AAesp03.gif
    AAesp03.gif
    10.4 KB · Views: 428
The registers on that chip are odd.... Really odd

Data

D7 D6 D5 D4 D3 D2 D1 D0

Segments
DP..A...B...C...D...E...F...G..

So to write 131 as you did

01100001.. Which is 0x61 or 97 decimal

If you turn decode on ( 0xff ) then if you write 2 then it displays 2
 
Hello Ian,

For a 7-segment i can understand, but for a led matrix 8x8 is it binary i think?

Why!!! Are you using a matrix?? I thought it was a row of 4 led common cathode LED's you were using.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top