Jump to content

Recommended Posts

I'm having trouble getting my PIC to put out a sequence fo 4 bytes. putc() doesnt seem to like 0x00. In a previous post, reynard said:

 

"You cannot use puts(*mybuffer) to send your message as it contains a null (0x00) within it which will terminate the transmission early."

 

Is there something similar with putc(0x00); ??

 

for example, i can successfully use the following to correctly display the entire alphabet...

 

putc(0x61); //a

putc(0x62); //b

...

putc(0x7a); //z

output: abcde...z

 

HOWEVER, when i substitute putc(0x00); for say 'c' it will skip a bunch of the other letters and maybe start up again with 'j' or 'k' and the results are seemingly random. It looks like it gets to the putc(0x00); and just gives up. Is there some kind of special case for the 0x00? i also tried doing it in stragiht assembly by repeating this block 4 times in a row. It will put out 4 'a's no problem, but it doesnt like the 0x00 when i try that.

 

asm //this is from memory, so there may be an error but it works just like putc() in my program, only longer and less efficient probably

{

updateMotor:

btfss _pir1, TXIF

goto updateMotor

movlw 0x80

movwf _txreg

nop

}

 

All i really need to do is send a sequence of 4 simple bytes to include at least one 0x00 (more probably 2 or 3).

Link to post
Share on other sites

I guess i'm not certain whether it's sending a nullchar or not, but i dont know if it matters. There are 2 recieving devices on the PIC's Tx line, PC and Motor controller. The PC is just so i can see if Tx/Rx is happening, and the Motor Controller is expecting 0x00.

 

The PC can't display the nullchar so it skips it. Sometimes when I putc() the whole alphabet and i replace the C with a 0x00 it will work 'correctly' and i'll get ABDEFG...Z. It just skips the 'C'. Other times, it skips 4 or 5 characters.

 

The Motor Controller is expecting plenty of 0x00s. In fact, the second byte of it's message is always a 0x00. It's here if you care to look at it: http://www.pololu.com/catalog/product/376/resources

 

I would think it's as simple as putc, putc, putc, putc but that doesnt seem to work. My thoughts are that when it gets to the 2nd byte of the message (the 0x00) it skips the remaining 2 bytes and no complete message is delivered. Also on that pololu website, there's an example program which says to make sure the PIC's WDT is OFF, does that make any kind of sense?

 

EDIT: This probably has nothing to do with a PIC and doesn't belong in this forum. I'll figure it out eventually.

Edited by toolrocket
Link to post
Share on other sites

Dude, I am all out of ideas. I assume you have configured your motor controller for the correct device so I won't ask.

 

The watchdog timer is ON by default, so turn it OFF in the CONFIG section while you are developing. Watchdog timers are nice to have in finished code just in case something does not quite go to plan in your software.

 

Try doing a wrap-around on the controller to see if you can recieve what you sent and compare the data. i.e. putc, getc, compare, putc, getc, compare, etc.

 

Cheers

 

Reynard

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...