Information-Micro Maestro 6ch PIC16f84A & MikroC at end

Just to be sure, how is it blinking? The possibilities are:

  • blinking very briefly (about 10% duty cycle) - no servo pulses are being sent and all output channels are low
  • double-blinking - servo pulses are being sent or an output is high
  • on for half a second / off for half a second - baud detect mode, waiting for 0xAA

Your connections sound right. How do you power the PIC?

Anyway, you need to either use compact protocol or put the 0xAA back in there. Also, I recommend not doing anything with TRISA at all, and checking whether your software UART library does it for you. You should be able to detect a high voltage on PA1 when the UART is enabled correctly. If you want to see the data getting sent on PA2, put an LED & resistor between that line and 5V - it will blink whenever bytes are sent.

-Paul

I put the LED inbetween GND and RA1, it lights up a little bit when the PIC isn’t powered. Just got an intermittent 10% duty cycle yellow and a red the error is serial protocol error

I think the LED i added is lighting up cause the maestro is sending some data, although it is still showing the 10% yellow LED

The Maestro will drive its TX line high most of the time, but it will not send data on its own without receiving a command. I suggest you check RA2 as I suggested to see whether the PIC is sending data.

How are you powering the PIC?

What code is generating the protocol error? I told you in my last response that your code was obviously wrong, so if you have not changed it, telling me that you are getting a serial protocol error is useless, and if you have changed it, you need to post the new code now if you expect to get help debugging it.

Also, before you never mentioned the red LED, so you must have changed something - what did you change?

-Paul

I can’t remember what i did when it started doing that. The PIC is running off a seperate 4.8v Rx battery. MAybe i need to go on a forum that specialises in the MikroC program to find it out.

This is the code:

void main() {
  TRISA=0;
  TRISB=0;
  while(1)
  {
  Soft_UART_Init(PORTA, 1, 2, 9600, 0);
//Soft_UART_Write(132);
Soft_UART_Write(0);
Soft_UART_Write(112);
Soft_UART_Write46);
Soft_UART_Break();
  PORTB=255;
  Delay_ms(500);
  PORTB=0;
  Delay_ms(500);
  }
  }

Had a response on the mikroC forum and gonna try that when i get home, just a case of putting 0b infront on the trisa & b values to tell it it is a binary value, otherwise it was thinking it was 3921 (01000000/255)

Your code, as written, will not even compile. It has a missing parenthesis before “46”. What is soft_uart_break() supposed to do? I did not see it in the MikroC manual.

Anyway, until you address the issues I mentioned, there is no chance that it will work: You need to try taking out those TRIS lines so that you do not damage the Maestro or your PIC, then finish switching to the compact protocol, which would start with a 0x84 or 132.

-Paul

can it detect baud rate in compact protocol?

In detect baud rate mode, you need to send a 0xAA first. After that, you can send your compact protocol command, beginning with 0x84.

-Paul

When i power the maestro up with the pic connected the red led flashes 4 times, what does this mean?

That indicates a brownout detect - the power supply for your Maestro dropped to a value below 4.5 V or so. Have you changed your power supply? Are you still setting TRIS to a value that will short out the Maestro?

-Paul

Changed the PORTA to &PORTA as i was told to do in the mikroe forum, now it works thanks for all your time and help!

I’ll put my final code in here incase it helps people in the future. This code worked.

void main() {
  TRISA=0b01010;   // Added 0b for binary
  TRISB=0b00000000;   // Added 0b for binary
  Soft_UART_Init(&PORTA, 1, 2, 9600, 0);
  Delay_ms(5000);
    while(1)
  {
  Soft_UART_Write(0xAA);
  Soft_UART_Write(12);
  Soft_UART_Write(4);
  Soft_UART_Write(0);
  Soft_UART_Write(112);
  Soft_UART_Write(46);
  ///Soft_UART_Write(132);
  ///Soft_UART_Write(0);
  ///Soft_UART_Write(112);
  ///Soft_UART_Write(46);
  Soft_UART_Break();
  PORTB=255;
  Delay_ms(500);
  PORTB=0;
  Delay_ms(500);
  }
  }

PIC16F84A Maestro Tx goes to RA1 pin and Rx goes to RA2

Well, I am glad you have it working now. Does it work in auto-baud-detect mode, or just at a fixed baud rate? I am still worried about how you set TRISA before initializing the software UART. I think that this is guaranteed to send a low pulse out on RA1 which could confuse the Maestro in some situations, especially if the start byte follows immediately. I have seen various examples that do not set TRISA at all - maybe you should try that.

Also, I still do recommend the compact protocol for applications using just a single Maestro.

Good luck with your project, and please let us know if you have more questions!
-Paul

Yeah it works in baud detect mode, will try the compact protocol. I am making board for programming via ICSP to stop plugging and unplugging the chip, the legs are getting worn out.

Do you mean remove the TRISA = 0b01010?

Yes, that is what I want you to try!
-Paul

Will do! gonna have a go at getting a PIC to read outputs from a Rx then feed it into the maestro