完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
所以我有一个带有两个 max485 屏蔽的 esp 来接收(改变)和发送 dmx 数据。然而,首先我只想接收并通过 DMX 信号,这样当我让它工作时,我就可以开始做我的 if 和 else。 然而,阅读 dmx 似乎并没有以我的经验开始工作。我基于此处找到的 espdmx 库发送(实际上已经有效): 我当前正在运行的代码: 代码:全选#include #include //ticker Library #include "espDMX2/espDMX.h" #define NUMBER_OF_CHANNELS 512 unsigned int dmxaddress = 1; #define DEpinTX D5 #define DEpinRX D6 #define btnPin 7 DMXESPSerial dmx; #define RX_PIN 3 // serial receive pin, which takes the incoming data from the MAX485. #define TX_PIN 2 // serial transmission pin /******************************* DMX variable declarations ********************************/ volatile byte i = 0; //dummy variable for dmxvalue[] volatile byte dmxreceived = 0; //the latest received value volatile unsigned int dmxcurrent = 0; //counter variable that is incremented every time we receive a value. volatile int currentBit = 0; volatile byte dmxvalue[NUMBER_OF_CHANNELS]; volatile int zeroCounter = 0; volatile int dmxnewvalue = 0; void setup() { //pinMode(RX_PIN, FUNCTION_3); WiFi.mode( WIFI_OFF ); WiFi.forceSleepBegin(); /******************************* Max485 configuration ***********************************/ Serial.begin(250000); pinMode(DEpinTX, OUTPUT); pinMode(DEpinRX, OUTPUT); digitalWrite(DEpinRX, LOW); digitalWrite(DEpinTX, HIGH); dmx.init(512); pinMode(RX_PIN, INPUT); //sets serial pin to receive data pinMode(TX_PIN, OUTPUT); timer1_attachInterrupt(onTimerISR); //function to call at 4us timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP); // 80 Mhz / 16 = 5 Mhz, 5 ticks / us -> 20 ticks = 4us, timer1_write(20); //4 us delay(2000); } //end setup() void loop() { // the processor gets parked here while the ISRs are doing their thing. if (dmxnewvalue == 1) { //when a new set of values are received, jump to action loop... for (int y = 0; y < NUMBER_OF_CHANNELS; y++) { dmx.write(y, interestingBytes[y]); } dmx.update(); dmxnewvalue = 0; zeroCounter = 0; //and then when finished reset variables and enable timer2 interrupt i = 0; } } //end loop() void onTimerISR() { if (digitalRead(RX_PIN)) { zeroCounter = 0; } else { zeroCounter++; if (zeroCounter == 20) { //80 us break (20 zero's in a row) attachInterrupt(digitalPinToInterrupt(RX_PIN), receptionISR, CHANGE); } } } void receptionISR() { dmxreceived = Serial.read(); dmxcurrent++; //increment address counter if (dmxcurrent > dmxaddress) { //check if the current address is the one we want. dmxvalue = dmxreceived; i++; if (i == NUMBER_OF_CHANNELS) { detachInterrupt(digitalPinToInterrupt(RX_PIN)); dmxnewvalue = 1; //set newvalue, so that the main code can be executed. } } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1140 浏览 1 评论
577浏览 6评论
478浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
462浏览 5评论
463浏览 4评论
439浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 23:32 , Processed in 0.793327 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号