Quantcast
Viewing all articles
Browse latest Browse all 116964

Forum Post: Can't send data within ISR

I can't seem to send any data inside my ISR for Port 1.  Here's my code:

***********************************************

void sendNewState(int newState)
{
char buf[9];
strcpy(buf, "datatosend");

int s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
tRemoteAddr.sa_family = AF_INET;
tRemoteAddr.sa_data[0] = (outport & 0xFF00) >> 8;
tRemoteAddr.sa_data[1] = (outport & 0x00FF);
tRemoteAddr.sa_data[2] = 192;
tRemoteAddr.sa_data[3] = 168;
tRemoteAddr.sa_data[4] = 1;
tRemoteAddr.sa_data[5] = 144;
connect(s, &tRemoteAddr, sizeof(tRemoteAddr));
__delay_cycles(100000);

send(s, buf, 9, 0);

__delay_cycles(10000);
closesocket(s);

}

main(void)

{

ulCC3000DHCP = 0;
ulCC3000Connected = 0;
ulSocket = 0;
ulSmartConfigFinished=0;

WDTCTL = WDTPW + WDTHOLD;

//
//Setup my interrupt
//
P1DIR |= BIT0; // Set P1.0 to output direction
P1OUT &= ~BIT0;
P1OUT &= ~BIT4; //
P1IES &= ~BIT4; // P1.4 Lo/Hi edge
P1IE = BIT4; // P1.4 interrupt enabled
P1IFG &= ~BIT4; // P1.4 IFG cleared

while(ulCC3000Connected == 0)
{

}

sendNewState(0); //init to 0 - THIS WORKS

// Set up listener on port 2002 (inport)

sockaddr sraddr;
long sr = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
sraddr.sa_family = AF_INET;
sraddr.sa_data[0] = (inport & 0xFF00) >> 8;
sraddr.sa_data[1] = (inport & 0x00FF);
memset (&sraddr.sa_data[2], 0, 4);

sockaddr clientaddr;
socklen_t addrlen;
bind(sr, &sraddr, sizeof(sockaddr));
__delay_cycles(100000);
listen(sr,0);

int numBytes;
char dataBuf[4];
int acceptResult = -1;

while (1)
{
__bis_SR_register(GIE); //LPM2_bits + GIE);
__no_operation();

//
// Handle any un-solicited event if required - the function shall be triggered
// few times in a second
//
hci_unsolicited_event_handler();

addrlen = sizeof(clientaddr);

while ( (acceptResult == -1) || (acceptResult == -2) )
{
    acceptResult = accept(sr, (sockaddr *) &clientaddr, &addrlen);
    hci_unsolicited_event_handler(); //??
}


if(acceptResult >= 0)
{
   //Do stuff with results

    acceptResult = -1; // reset to run through accept loop again
}

}


}

// Interrupt Service Routines

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{

P1OUT ^= BIT0; // P1.0 = toggle
sendNewState(0); - THIS DOES NOT WORK
__delay_cycles(24000000); // Crude debouncing
P1IFG &= ~BIT4; // Clear P1.4 IFG
}

****************************************************************'

When I take sendNewState() out of my ISR, everything works perfectly.  When I put sendNewState() back in, everything gets hung up.  When I comment out the contents of sendNewState() and add it back in line by line to try to find the issue, the code hangs on "int s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"  

Any ideas why my interrupt isn't playing nice?


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>