Jec, good find thanks for the info!
@dynamoben
Can you explain to me this code for 1 chanel?
it was yours i have found it in the forum
DimmerCount VAR WORD ; Location in DMX string
DMXStartAddr VAR WORD ; DMX start address
DMXStartCode VAR BYTE ; DMX Start code (Dimmer=0)
Dummy VAR BYTE
DMX_State VAR BYTE ; Stage of DMX reception
Valid_Break CON 1
Valid_SC CON 2
Valid_Data CON 3
Disable
INTERRUPT_SUB:
IF OERR Then
CREN = 0
CREN = 1 ; Clear Overrun Errors
High Err_LED ; Notify user of overrun error
DMX_State=0
EndIF
IF FERR Then
FERR = 0
DMX_State=Valid_Break
Else
GoSub RX_DMX_Data
EndIF
Dummy=RCREG ; Empty UART of junk data
Resume
RX_DMX_Data:
IF DMX_State=Valid_Break Then
HSerin 20,NoData,[DMXStartCode] ; Start code of 0 = dimmer data
IF DMXStartCode=0 Then
DMX_State=Valid_SC
Else
High Err_LED ; Notify user of Error in Start Code
DMX_State=0
EndIF
EndIF
IF DMX_State=Valid_SC Then
For DimmerCount=0 TO DMXStartAddr; Count incoming data bytes (frames)
Dummy=RCREG ; Read unwanted values
Next DimmerCount
DMX_State=Valid_Data
EndIF
IF DMX_State=Valid_Data Then
HSerin 20,NoData,[STR DataBuffer\Number_Of_Channels]
DMX_State=0
EndIF
IF DMX_State=0 Then
Resume
EndIF
GoTo RX_DMX_Data
NoData:
DMX_State=0
Resume
Enable
End
That is the same code that you put in post #1.
As I explained before, that is only a code chunk, a small part of a much larger project. And quite frankly, if that code was the whole thing, it is fairly well commented and/or self-explanatory.
Do you know how DMX works? Do you know the basics of it's protocol?
Skimask is correct. If you have a complete understanding of the DMX protocol the code I posted should make sense. The Microchip application note mentioned above has a document that talks about how to receive DMX. Their explanation and what I'm doing in my code match.
You have to have a complete understanding of DMX before you can write/understand any of this code. Once you have that its pretty simple, a short cut would be to use Microchips example code in your project. (see ASM command)
Last edited by DynamoBen; - 17th May 2007 at 18:26.
I got a question for you about this chunk of the code:
IF DMX_State=Valid_SC Then
For DimmerCount=0 TO DMXStartAddr; Count incoming data bytes (frames)
Dummy=RCREG ; Read unwanted values
Next DimmerCount
DMX_State=Valid_Data
EndIF
Does it just happen to work because the baud rate is fast enough that the loop almost can't keep up? How do you know that 'Dummy' always gets loaded with valid data (in this case the unwanted values) from RCREG instead of the same thing that was there last time around in the loop before the next byte actually arrives.
I would figure that the code would at least poll the RCIF flag and THEN get a new byte from RCREG.
Just curious...have no need to know, not building any projects anytime soon...(and this all ties back into my post #4 about the bugs...but you probably already figured that out...)
Well the big thing that is missing here is the fact that this was snipped from an interrupt sub. All my code is interrupt based...to be honest I have actually since scaled back this code to make it a little simpler. I stripped out all the status checks and just bounce from one hserin command to another until I have the values I need.
Bookmarks