gouravzutshi 0 Posted July 13, 2014 Share Posted July 13, 2014 Hello everyone I wrote the following code to run a stepper motor in arduino depending upon a UART signal. The UART signal came from processing 2 code. Now instead of an arduino board i want to run the same code on my TIVA C series tm4c123gh6m launch pad what should i do. Note- I used digital pins 8,9,10,11 of the arduino to run the motor. What does 8,9,10,11 refer to in tiva C series? int a=8; int b=9; int c=10; int d=11; void setup() { Serial.begin(9600); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); establishContact(); } void loop() { int tex; tex=Serial.read(); if(tex=='A') { digitalWrite(a,LOW); digitalWrite(b,HIGH); digitalWrite(c,LOW); digitalWrite(d,HIGH); delay(5); digitalWrite(a,LOW); digitalWrite(b,HIGH); digitalWrite(c,HIGH); digitalWrite(d,LOW); delay(5); digitalWrite(a,HIGH); digitalWrite(b,LOW); digitalWrite(c,HIGH); digitalWrite(d,LOW); delay(5); digitalWrite(a,HIGH); digitalWrite(b,LOW); digitalWrite(c,LOW); digitalWrite(d,HIGH); delay(5); } } void establishContact() { while (Serial.available() <= 0) { Serial.write('A'); // send a capital A delay(300); } } Quote Link to post Share on other sites
spirilis 1,265 Posted July 13, 2014 Share Posted July 13, 2014 It might work fine out of the box as-is, after you tweak the pin assignments (if it's even necessary). Note you can afford to jump the Serial bitrate up to 115200 (need to do that on both ends, the Processing side and sketch). Quote Link to post Share on other sites
spirilis 1,265 Posted July 13, 2014 Share Posted July 13, 2014 As for the pin assignments, please see this page for a diagram: http://energia.nu/pin-maps/guide_stellarislaunchpad/ (note the Stellaris LaunchPad pinout is identical to the Tiva TM4C123GXL LaunchPad). Quote Link to post Share on other sites
gouravzutshi 0 Posted July 13, 2014 Author Share Posted July 13, 2014 Sir, I intend to use PB7, PB6, PB5, and PB4, to run the stepper motor. For arduino i used pins 8,9,10,11. What changes should i make to the code so that it is configured for PB7, PB6, PB5, PB4 pins. And do we need to initialise all registers (like AFSEL, AMSEL, etc), like it's done in keil. Quote Link to post Share on other sites
L.R.A 78 Posted July 13, 2014 Share Posted July 13, 2014 Sir, I intend to use PB7, PB6, PB5, and PB4, to run the stepper motor. For arduino i used pins 8,9,10,11. What changes should i make to the code so that it is configured for PB7, PB6, PB5, PB4 pins. And do we need to initialise all registers (like AFSEL, AMSEL, etc), like it's done in keil. you can use the macro PB_7, PB_6, PB_5 and PB_4. You also can use numbers but i never know wich ones they are, it's easier to use the leters and numbers macros Quote Link to post Share on other sites
energia 484 Posted July 13, 2014 Share Posted July 13, 2014 Maybe the numbers are not clearly explained in the pin map but the pin numbers are the numbers in the black cells. PB7 -> 15 PB6 -> 14 PB5 -> 2 PB5 -> 7 Quote Link to post Share on other sites
SixSixSevenSeven 23 Posted July 13, 2014 Share Posted July 13, 2014 Sir, I intend to use PB7, PB6, PB5, and PB4, to run the stepper motor. For arduino i used pins 8,9,10,11. What changes should i make to the code so that it is configured for PB7, PB6, PB5, PB4 pins. And do we need to initialise all registers (like AFSEL, AMSEL, etc), like it's done in keil. int a=8; int b=9; int c=10; int d=11; Can simply be changed to int a=PB_7; int b=PB_6; int c=PB_5; int d=PB_4; If you are using energia. You do not need to initialise any registers. Energia can be considered as arduino for msp430 and tiva c. You never had to initialise registers on your old arduino board did you? Energia & Arduino both abstract that away from you. With the change I just stuck above your code verifies just fine in energia. @@spirilis has linked you to the pinout guide. You will notice pins are given both a number, port name and a few have extra names ontop of that too. We'll take the pin the red LED is connected to as an example. int ledPin = RED_LED; int ledPin = PF_1; int ledPin = 30; all 3 are valid options for referring to pin 30 on the tiva c launchpad. Quote Link to post Share on other sites
spirilis 1,265 Posted July 19, 2014 Share Posted July 19, 2014 Don't forget the underscore, i.e. int a=PB_7; ... those Px_y constants are just aliases of the requisite Energia pin# fwiw. edit: nm you showed that in the 2nd example Quote Link to post Share on other sites
SixSixSevenSeven 23 Posted July 19, 2014 Share Posted July 19, 2014 Don't forget the underscore, i.e. int a=PB_7; ... those Px_y constants are just aliases of the requisite Energia pin# fwiw. edit: nm you showed that in the 2nd example Whoops, fixed for first part too Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.