Hello again,
I'm having difficulty sending packets from my CC3000 with a size larger than 128 bytes. The documentation on the CC3000 send() function seems to indicate that the maximum size of a data packet is about 1400 bytes, but I can't get anywhere near that. When I call the send function with a size greater than ~128 bytes, the microcontroller hangs and requires a hard-reset. On my client side, no data is received and the "read" request eventually times out.
I'm modifying the sensor example. I'm trying to use the ADC to convert data from a microphone at ~22.05 kHz and send the raw data in packets of reasonable size to my computer for audio output. The only real modification I made was to server.c:
At the top:
#define PACKET_SAMPLES 64 // 64 shorts = 128 bytes OK. 128 shorts = 256 bytes fails send()
unsigned short packetPrefix = 0x0DBE; // ( '\r', 0xBE' )
unsigned short packetSuffix = 0xEF00; // ( 0xEF, 0x00 )
unsigned short dataPacket[ PACKET_SAMPLES + 2 ]; // 132 bytes
volatile unsigned int adcVal = 0;
And further down:
// Check whether we received the DATA command from the client
// telling us to begin sending data to it.
if(strncmp(requestBuffer,"DATA",strlen("DATA")) == 0)
{
// Set up the microphone pin for input to ADC
P3OUT &= ~BIT0; // Set P3.0 to low
P3DIR &= ~BIT0; // Set P3.0 to Input
P3REN |= BIT0; // Enables a pulldown resistor on P3.0
P3SEL0 &= ~BIT0; // Enable GPIO on P3.0
P3SEL1 &= ~BIT0; // Enable GPIO on P3.0
P3DIR &= ~BIT0; // Set P3.0 to Input... again?
// Copy the packet prefix and suffix
dataPacket[ 0 ] = packetPrefix;
dataPacket[ ( sizeof( dataPacket ) / sizeof( short ) ) - 1 ] = packetSuffix;
while(currentCC3000State() & CC3000_CLIENT_CONNECTED)
{
// Start Sending Data to server
// Send data to CC3000
hci_unsolicited_event_handler();
unsolicicted_events_timer_disable();
toggleLed(CC3000_SENDING_DATA_IND);
// Set up ADC to sample from microphone pin
ADC10CTL0 &= ~ADC10ENC; // Ensure ENC is clear
ADC10CTL0 = ADC10ON + ADC10SHT_5; // Set up 96 ADC10CLK cycles for sample and hold
ADC10CTL1 = ADC10SHP + ADC10CONSEQ_0; // Consider setting this to ADC10CONSEQ_2
ADC10CTL2 = ADC10RES; // Set 10 bit resolution
ADC10MCTL0 = ADC10INCH_13; // Select P3.0 as ADC input
ADC10IV = 0x00; // Clear all ADC10 channel int flags
// Fill the data packet
for( pidx = 0; pidx < PACKET_SAMPLES; pidx++ )
{
ADC10IFG = 0;
ADC10CTL0 &= ~ADC10ENC;
ADC10CTL0 &= ~ADC10SC;
ADC10CTL0 |= ADC10ENC + ADC10SC ; // Start conversion
while( ADC10CTL1 & BUSY ); // Wait for conversion to finish...
adcVal = ADC10MEM0<<4; // Shift this right four
dataPacket[ 1 + pidx ] = ( short )adcVal;
__no_operation(); // Debug?
}
__no_operation();
bytesSent = send(clientDescriptor, (unsigned char *)dataPacket, sizeof(dataPacket), 0);
if (bytesSent != sizeof(dataPacket))
{
bytesSent = send(clientDescriptor, (unsigned char *)dataPacket, sizeof(dataPacket), 0);
if (bytesSent != sizeof(dataPacket))
{
// Check if socket is still available
curSocket = getsockopt(clientDescriptor, SOL_SOCKET, SOCKOPT_NONBLOCK , &optval, (socklen_t*)&optlen);
if (curSocket != 0)
{
closesocket(clientDescriptor);
terminalPrint("Client Disconnected\r\n");
clientDescriptor = -1;
unsetCC3000MachineState(CC3000_CLIENT_CONNECTED);
}
}
}
unsolicicted_events_timer_init();
}
Let me know if you see anything blatently wrong. One thing I think might be an issue is the fact that this application seems to fill the ram almost entirely. I can't actually allocate a 1k array (512 shorts) in the stack because the 16k of RAM appears to be mostly used... This would be great because there appears to be quite a bit of overhead involved with actually sending a packet from the CC3000 (the ADC conversion rate is not the factor keeping me from real-time operation -- the packet rate is...)
Thanks in advance for any help!
-Griff