here is the code I can run sofar:
This reads from the ADC (still called every ms). This just reads the values from the adc into a buffer of 40 longs. After 40 ms, it sets a flag, sBuff.
- Code: Select all
void read_ad_data()
{
byte input[4];
byte instr=192;
write_ads1210(instr,input,0);
pinMode(SDIO,INPUT);
int sclk,D0;
adc_val= 0;
for(sclk=(NBIT-1); sclk>=0; sclk--)
{
digitalWrite(SCLK,HIGH);
D0=digitalRead(SDIO);
if(D0==HIGH)
adc_val+=pow2[sclk];
// Serial.print(D0,DEC);
digitalWrite(SCLK,LOW);
//Serial.println();
}
//Serial.write((unsigned byte*)&adc_val,4);
if(lenbuff<40)
{
buff[lenbuff++]=adc_val;
}
if(lenbuff>39)
{
lenbuff=40;
sBuff=1;
}
}
The sending is done here. Basically all it does is, whenever the ADC sets the "buffer ready" alias sBuff flag to 1 and the wishield cares to execute this function, to send the buffer off to the socket, reset the flag and the buffer.
- Code: Select all
void socket_app_appcall(void)
{
/*
* If a new connection was just established, we should initialize
* the protosocket in our applications' state structure.
*/
if(uip_connected()) {
sock = &(uip_conn->appstate);
}
if(uip_closed() || uip_aborted() || uip_timedout()) {
sock = NULL;
}
if(sBuff>0)
{
if(uip_poll()) {
uip_send(buff, lenbuff* sizeof(long));
}
lenbuff=0;
sBuff=0;
}
/*
if(uip_acked()) {
if(lenbuff < uip_mss()) {
lenbuff = 0;
memset(buff, 0, 10 * sizeof(long));
}
else {
lenbuff -= uip_mss();
memmove(buff, buff + uip_mss(), lenbuff);
uip_send(buff, lenbuff);
}
}
*/
}
This works relatively stable and I do get indeed 40 longs on my receiver side. But again, it take 300 ms for the 40 longs or 160 bytes to arrive and so my overall performance again is "magically" reduced to 500 bytes/s. How is that possible? No matter what I do, I wont get more than that.