Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
I am writing an app that translates ART-NET dmx to the LT8500 48 channel pwm driver. I got it working, but now the mbed hangs on the net::poll() command, and it is pretty much packet-rate dependent. The more udp packets that get sent to it, the quicker it fails. I think there has got to be some kind of memory buffer that I need to manually flush. Any insights?
#include "mbed.h" #include "EthernetNetIf.h" #include "DmxArtNet.h" Ticker PWMCLK; DigitalOut myClock(p20); DigitalOut myled(LED1); DigitalIn checkPin(p19); DigitalOut led3(LED3); DigitalOut led2(LED2); PwmOut twentyone(p21); SPI spi(p11, p12, p13); // mosi, miso, sclk DigitalOut LDI(p16); Serial pc(USBTX, USBRX); // tx, rx int numbits =3; const int spiFormat=0; const int spiFreq = 1000000; DmxArtNet art; EthernetNetIf eth; EthernetErr ethErr = eth.setup(20000); IpAddr myIp = eth.getIp(); void Pulse() { myClock=!myClock; led2=myClock; } void send(){ LDI=0; wait_us(20); LDI=1; wait_us(2); LDI=0; wait_us(10); } void WriteValues(int value){ int p =0 ; int test_value = 500; spi.format(12,spiFormat); for (int i = 0;i<48;i++) { numbits+=8; p=spi.write(value); //pc.printf("I just wrote this value: %d and read this one : %d \n",i*100, p); } } void WriteValuesArt(int value[48]){ spi.format(12,spiFormat); for (int i = 0;i<48;i++) { spi.write(16*value[47-i]); } } int WriteCommand(int Command){ spi.format(8,spiFormat); int spiread = 0; switch (Command) { case 1://output enable spiread = spi.write(0x30); break; case 2: //correction frame spiread = spi.write(0x20); break; case 3: // asychronus update frame spiread = spi.write(0x10); break; case 4: // selftest spiread = spi.write(0x50); break; default: spiread = spi.write(0); //defaults to sych update break; } send(); numbits +=8; // pc.printf("I sent a total of %d bits\n",numbits); numbits=0; return spiread; } int main() { LDI=1; twentyone.period_us(1); twentyone=0.5; wait(1); pc.printf("my ip is %d.%d.%d.%d\n", myIp[0],myIp[1],myIp[2],myIp[3]); art.BindIpAddress = myIp; art.BCastAddress = IpAddr(255,255,255,255); art.InitArtPollReplyDefaults(); art.ArtPollReply.PortType[0] = 0; // output art.ArtPollReply.PortType[1] = 512; // input art.ArtPollReply.GoodInput[2] = 4; memcpy(&art.ArtPollReply.Addr, &myIp, sizeof(myIp)); art.Init(); art.SendArtPollReply(); // announce to art-net nodes int u = 0; spi.format(8,spiFormat); spi.frequency(spiFreq); LDI=0; while(checkPin){ // pc.printf("I am checking da pin!\n"); } pc.printf("found it!\n"); myClock =1; WriteValues(0); WriteCommand(2); WriteValues(0); WriteCommand(3); WriteValues(4000); WriteCommand(1); int counter=0; led3=1; int dir = 1; int lt8500[48]= {0}; Timer T; T.start(); while(1) { Net::poll(); if (art.Work()) { //pc.printf("found work\n"); for (int i = 0; i < 48; i ++) { int cycle =0; cycle=art.DmxIn[0][i]; lt8500[i]=cycle; WriteValuesArt(lt8500); WriteCommand(3); // pc.printf("I made it to cycle %d\n",i); }} pc.printf("did I make it here\n"); int k, j, dmx; for (k = 0; k < 16; k ++) { for (j = 0; j < 512; j ++) { dmx = art.DmxIn[k][j]; }} //pc.printf(art.LastErrorString()); if (T.read() >10.00 ){ art.SendArtPollReply(); // announce to art-net nodes T.stop(); T.reset(); T.start(); pc.printf("timer set\n"); } } }