Author Topic: Serial Transmit Port Use  (Read 3471 times)

Redwolf92

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Serial Transmit Port Use
« on: February 03, 2015, 06:01:17 AM »
Hello,

My code that I am questioning verified in the Arduino IDE just fine, but I would like a second opinion as to what I am doing. I declared my TX pin in the serial.begin statement of my code, and I also use the TX pin as an input. Is this going to work or just totally flop? I am using the RFduino to read the RPM from a motor and also "program" it to run a different speed by sending a reference byte. The way the system is set up is that there is one data line between RFduino and motor. This line has a signal to be translated to rpm on it when the motor is not being "programmed" ie, the motors micro-controller is not interrupted. So the code is using digitalRead(TXpin) when reading the rpm from the motor, and using Serial.write((byte)) when sending the reference byte to the motor.

Thank you for any input

tolson

  • Global Moderator
  • *****
  • Posts: 831
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: Serial Transmit Port Use
« Reply #1 on: February 03, 2015, 11:29:35 AM »
Hi Redwold92,
I can visualize about a half dozen ways you might have wired things to do what I think you are saying. Can you give a schematic of exactly how you have wired your project. Be sure to include part numbers for controller chips, etc.

You can't generally use serial.begin defining a TX pin and then arbitrarily define the TX pin as an input without dealing with the configuration that serial.begin set up.  But I can't say for sure what you should do as I can' visualize your setup.

Redwolf92

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Serial Transmit Port Use
« Reply #2 on: February 03, 2015, 04:18:44 PM »
Thank you for helping tolson,

The PIC16F676 assembly code is set up to read the speed reference byte it receives on the data line as you can hopefully see in my drawing. It correctly does this communication already between a handheld unit connected via a usb. My project is to make this wireless to a smartphone. The wired way is PIC16F676 to PIC16F676 communication. The speed reference byte will be 00 to 06 hex in my prototypes case of which the PIC will compare to a retlw table and change speeds. The data line it receives the reference byte is set up to strobe at a frequency relate-able to one half revolution of the rotor in the motor and I am already able to read this signal with the RFduino by using a reciprocal frequency calculator method. I am using the smartphones as the RFduino's master so I plan on sending a byte to the RFduino from the smartphone of which the RFduino relates to a speed reference byte and then communicates this to the motor. Ive been thinking more about it and I guess would it be alright to call serial.begin(9600,0,5) in the on receive? Then once communication is done with the motor revert back to the original pinout? Or do you think it would just be easier to write a loop to transmit the reference byte by just "manually" switching the GPIO's and not even bother with changing the serial TX port.

tolson

  • Global Moderator
  • *****
  • Posts: 831
  • Karma: +19/-0
    • View Profile
    • Thomas Olson Consulting
Re: Serial Transmit Port Use
« Reply #3 on: February 03, 2015, 05:26:22 PM »
Sorry, I still don't get it. Your schematic shows a clock and data for serial. Yet Serial library doesn't do that.

You might want to think about bit-banging your protocol.


Redwolf92

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Serial Transmit Port Use
« Reply #4 on: February 03, 2015, 05:57:26 PM »
Thank you,

That is the second opinion I needed. Im new to this type of thing, and I think I will just stay away from the serial port then and do it the way you said.

Redwolf92

  • RFduino Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Serial Transmit Port Use
« Reply #5 on: February 17, 2015, 02:39:28 PM »
I have one more question, I have figured out my own protocol for programming my motor and it works perfectly fine with the ios app I am creating as well. My only problem is the RFduino does not seem to be returning and running the loop. In the void loop() I have the Rfduino performing a reciprocal frequency counter to find the RPM of the motor and it broadcasts it as a float every half second. The iphone app picks this up and displays it perfecly, but once I specify a new speed to run the broadcast of the RPM stops completely. In the void RFduinoBLE_onReceive() all im doing is distinguishing which byte the iphone sent and pairing it with the bit banging code to program the motor to run a certain speed. Its just an if and a bunch of else if statements.

Is there anything I am missing? It seems like the RFduino isnt returning to the void loop() as it wont even broadcast RPM = 0. I know return is useless because it is a void function. After it runs the onReceive the RFduino kind of just craps out and pulls my data pin to 1 volt. Please tell me Im missing something simple as this would be a really inconvenient bug. The onReceive works multiple times in a row just fine and I should make a note that the data transmit line for the RPM readout and the programming is one and the same. In order get the RPM readout working again the RFduino needs to be restarted.