I believe you have to calculate the CRC and include it in your packet, also I would recommend to sniff the serial communication with a logic analyser.
I have a very simple snippet of an earlier test code while building a library years ago, perhaps this can help (see below) Regards, --Antonio openz1.m ************************************* function [s] = openz1(COMX, name) % Configures and open the serial port % to communicate with Zolertia Z1 mote % Arguments: % COMX = COMM port assigned to the mote s = serial(COMX); s.Baudrate = 115200; s.Name = name; s.Terminator = 'LF'; s.DataBits = 8; s.Parity = 'none'; s.StopBits = 1; s.OutputBufferSize = 50960; s.InputBufferSize = 50960; s.ReadAsyncMode = 'continuous'; fopen(s) if s.Status == 'open' fprintf('Z1 (%s) connected to serial port %s\n', s.Name, s.Port); else disp('Failed to connect Z1, closing') closeZ1(s); end *********************************************** send.m *********************************************** clc; clear all; close all; try %% Open the serial port [BS] = openz1('/dev/ttyUSB2', 'BS'); catch except display('Unexpected error, Closing'); newobjs = instrfind; fclose(newobjs); clear all; close all; clc; end %% Create the packet (no CRC) A = [126, 68, 38, 00, 00, 02, 00, 255, 13, 00, 67, 02, 50, 99, 00, 00, 00, 88, 00, 00, 00, 00, 00, 00, 0, 0, 126]; %% Compute CRCs % PAYLOAD CRC : From byte 12 to 22 aux = 0; for i = 11:1:21 aux = bitxor(aux, A(1,i+1)); end [A(1,23) A(1,23)] = deal(bitshift(aux,-8)); A(1,24) = bitand(aux,255); % PACKET PAYLOAD: 23 bytes lenght for packet CRC, starting from byte 2 crc = uint16(0); temp = uint16(0); for i = 1:1:23 buf = uint16(A(1,i+1)); buf = bitshift(buf,8); crc = bitxor(crc,buf); for j = 1:1:8 if crc >= 32768 temp = bitxor(bitshift(crc,1),4129); else temp = bitshift(crc,1); end crc = temp; end end A(1,25) = bitand(crc,255); A(1,26) = bitshift(bitand(crc,65280),-8); fwrite(BS,A,'uchar') ******************************************************* On Mon, Mar 18, 2013 at 5:02 AM, Jiang Lu <j...@crimson.ua.edu> wrote: > Hi > > I am writing a Matlab code for reading and writing data through serial > port. Now, the reading is working, but writing is not. > > In Tinyos part, I followed the Lesson 4, Mote-PC serial communication, by > changing BlinkToRadioAppC.nc to > > //components ActiveMessageC; > //components new AMSenderC(AM_BLINKTORADIO); > //components new AMReceiverC(AM_BLINKTORADIO); > components SerialActiveMessageC; > components new SerialAMSenderC(AM_BLINKTORADIO); > components new SerialAMReceiverC(AM_BLINKTORADIO); > > App.Packet -> SerialAMSenderC.Packet; > App.AMPacket -> SerialAMSenderC.AMPacket; > App.AMControl -> SerialActiveMessageC; > App.AMSend -> SerialAMSenderC.AMSend; > App.Receive -> SerialAMReceiverC.Receive; > > In Matlab part : > > s = serial('COM11','BaudRate',57600,'DataBits',8); > fopen(s); > write_data = [0 255 255 0 0 4 0 6 0 1 0 1 ]; > > % 0 synByte > % 255 Destination Addr > % 255 Destination Addr > % 0 Link Source addr > % 0 Link Source addr > % 4 Message length > % 0 Group ID > % 6 am handler > % 0 TOS node id > % 1 TOS node id > % 0 counter > % 1 counter > > fwrite(s,write_data,'uint8'); > fclose(s); > > This should send data back to serial and in BlinkToRadioC.nc the > Receive.receive should receive payload and setLeds(0x01) which means led 0 > on. > > But no data is received! > > Any suggestion? > > Thanks > > JL > > _______________________________________________ > Tinyos-help mailing list > Tinyos-help@millennium.berkeley.edu > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > -- -- Antonio LiƱan Colina R+D+I Engineer @: ali...@advancare.com @: ali...@zolertia.com ------------------------------ Advancare T: +34 93 582 02 70 http://www.advancare.com http://www.zolertia.com http://zolertia.sourceforge.net http://webshop.zolertia.com
_______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help