oadna
February 3, 2014, 1:12pm
1
Hello everybody,
I have a problem with mit w5100.
I want to send a byte array look like this uint8_t data[8] = {0x62, 0xC8, 0x03, 0xC8, 0x00, 0x43, 0xC8, 0x00};
And now there is the problem, when I send this array the first 4 bytes were send, but after 0x00 all position wont be send.
Do I have to escape this 0x00?
Does anyone know how I can fix the problem?
greetings
suhwan
February 4, 2014, 12:37am
2
Hi oadna,
W5100 can send a zero (0x00).
Please, check data length, data copy or updating Sn_TX_WR in your code.
Reference Code is [url]http://www.wiznet.co.kr/sub_modules/kr/product/product_detail.asp?Refid=677&page=1&cate1=5&cate2=7&cate3=26&pid=1019&cType=2[/url] .
uint16 send(
SOCKET s, /**< the socket index */
const uint8 * buf, /**< a pointer to data */
uint16 len /**< the data size to be send */
)
{
uint8 status=0;
uint16 ret=0;
uint16 freesize=0;
if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size.
else ret = len;
// if freebuf is available, start.
do
{
freesize = getSn_TX_FSR(s);
status = IINCHIP_READ(Sn_SR(s));
if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT))
{
ret = 0;
break;
}
} while (freesize < ret);
// copy data
send_data_processing(s, (uint8 *)buf, ret);
IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND);
/* +20071122[chungs]:wait to process the command... */
while( IINCHIP_READ(Sn_CR(s)) )
;
/* ------- */
#ifdef __DEF_IINCHIP_INT__
while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
#else
while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK )
#endif
{
/* m2008.01 [bj] : reduce code */
if ( IINCHIP_READ(Sn_SR(s)) == SOCK_CLOSED )
{
#ifdef __DEF_IINCHIP_DBG__
printf("SOCK_CLOSED.\r\n");
#endif
close(s);
return 0;
}
}
#ifdef __DEF_IINCHIP_INT__
putISR(s, getISR(s) & (~Sn_IR_SEND_OK));
#else
IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK);
#endif
return ret;
}
void send_data_processing(SOCKET s, uint8 *data, uint16 len)
{
uint16 ptr;
/* read Sn_TX_WritePointer */
ptr = IINCHIP_READ(Sn_TX_WR0(s));
ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_TX_WR0(s) + 1);
write_data(s, data, (uint8 *)(ptr), len);
ptr += len;
/* update Sn_TX_WritePointer */
IINCHIP_WRITE(Sn_TX_WR0(s),(uint8)((ptr & 0xff00) >> 8));
IINCHIP_WRITE((Sn_TX_WR0(s) + 1),(uint8)(ptr & 0x00ff));
}
Thanks
oadna
February 4, 2014, 7:23pm
3
he, thanks for your reply.
I have tried it again and again, but it doesn`t work.
When i remove the 0x00 from the array, the whole array will be sent.
This is so crazy.
greets
suhwan
February 5, 2014, 12:08am
4
Hi oadna,
Please, attach your code.
We will review the code.
Thanks,
oadna
February 5, 2014, 10:29am
5
Hello
I attached the file, I hope you can find the error.
Thank you.
WebClient.c (17.4 KB)
suhwan
February 6, 2014, 12:01am
6
Hi oadna,
We may find the error. :0
strlen
size_t strlen ( const char * str );
Get string length
Returns the length of the C string str.
The length of a C string is determined by the terminating null-character
So, your code should be change, as below
replace ‘strlen’ to ‘sizeof’
input data length directly
/* your code */
uint8_t data[8] = {0x62, 0xC8, 0x03, 0xC8, 0x00, 0x43, 0xC8, 0x00};
uint8_t end[2];
sprintf((char *) end, "\n\r");
if (send(sockreg,data,strlen((char *)data)) <= 0) break; //send data <= here
printf((char *)data);
_delay_ms(100);
if (send(sockreg,end,strlen((char *)end)) <= 0) break; //send end <= here
_delay_ms(1000);
/*fix code*/
//if (send(sockreg,data, sizeof((char *)data)) <= 0) break; //send data
if (send(sockreg,data, 8)) <= 0) break; //send data
printf((char *)data);
_delay_ms(100);
//if (send(sockreg,end, sizeof((char *)end)) <= 0) break; //send end
if (send(sockreg,end, 2)) <= 0) break; //send end
_delay_ms(1000);
Thanks
Thanks,
oadna
February 6, 2014, 11:42am
7
hi suhwan,
You helped me so much, thank you a lot.
Now my thesis is save.
greets