Sending data to DMX512

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
dnaci
Posts: 21
Joined: 09 Apr 2012 18:10

Sending data to DMX512

#1 Post by dnaci » 24 Apr 2024 15:18

I need to transfer the data coming via TCP to the DMX512 system. Actually, my code works, but I am having problems transferring the incoming data according to the DMX512 channel number to the relevant channel. I used for next but the data was mixed up. Steps 4-5 with the code snippet below. I send data to the channels without any problems. But I need to do it with for next or an alternative method. I do not want to use the ready dmx512 library because it gives errors.
I would be happy if you help.

Uart_Write(ch[0]) 'this sender code is working
Uart_Write(ch[1])
Uart_Write(ch[2])
Uart_Write(channel)
Uart_Write(data1)
Uart_Write(ch[5])
Uart_Write(ch[6])

My code:

Code: Select all

Dim    ch as byte[512]
Sub procedure sendframe()
t=0
tcpdata[0] = tcpdata[0] - 48
tcpdata[1] = tcpdata[1] - 48
tcpdata[2] = tcpdata[2] - 48
tcpdata[3] = tcpdata[3] - 48
tcpdata[4] = tcpdata[4] - 48
tcpdata[5] = tcpdata[5] - 48

channel = (tcpdata[0] * 100) + (tcpdata[1]  * 10) + tcpdata[2] 'tcp will be the first 3 data channel numbers
data1   = (tcpdata[3] * 100) + (tcpdata[4]  * 10) + tcpdata[5]  'tcp 4-5-6 data will be data

RCSTA.7= 0 'disable UART
PORTB.1=0  'low for frame start sync, Break
Delay_us(120)  '88us min required, 120us is safer.
PORTB.1=1 'high for mark after break
Delay_us(8)    '8usec min required
RCSTA.7= 1   'Enable UART

Uart_Write(0) 'DMX512 Start Code. Already includes the start bit.
Delay_us(36)  'let the serial data1 finish
RCSTA.7= 0
PORTB.1=1 'high for two stop bits and MTBF
Delay_us(4)
RCSTA.7= 1   'Enable UART

for t = 0 to channel - 1  'my problem is for next
Uart_Write(ch[t])
next t

Uart_Write(data1)

'Uart_Write(ch[0]) 'this code is working'
'Uart_Write(ch[1])
'Uart_Write(ch[2])
'Uart_Write(channel)
'Uart_Write(data1)
'Uart_Write(ch[5])
'Uart_Write(ch[6])

Delay_us(36)  'let the serial data1 finish
RCSTA.7= 0
PORTB.1=1 'high for two stop bits and MTBF
Delay_us(4)

End Sub

dnaci
Posts: 21
Joined: 09 Apr 2012 18:10

Re: Sending data to DMX512

#2 Post by dnaci » 26 Apr 2024 16:48

I solved the problem. I did not use RCSTA=0 after uart_write.

Post Reply

Return to “mikroBasic PRO for PIC General”