Computation


PSoC 420 Prototyping Kit

tl;dr This is not super intuitive to make work. At $4, this it is an amazing buy, but maybe you can skip coffee and get something that is a little more expensive.

The PSoC prototyping kit requires PSoC Creator software. I also used Bootloader.hex and Bootloader.hex files to use a UART-based bootloader. When starting a new project, pick the PSoC Design. Make sure the Application Type is "Bootloadable."

When working, you have three file types

  1. TopDesign.cysch -> contains components and connection in your design
  2. mtm.cydwr -> routing info, clocks, interrupts
  3. main.c -> c language main file

To start, add components into TopDesign.cysch from a component catalog. I added a digital output pin, bootloadable, and UART.

You can then configure each of the components. For my LED pin, I had to unclick HW Connection because I was using an LED on the PSoC board.

Any pin you place is a "virtual pin" that won't do anything unless you link it to a physical pin. Here, I connected the LED pin, tx, and rx uart connections. The schematic of the microcontroller is on the left.

Then, you go to the main file, and write your code inside the for loop. Use the datasheet inside each component (or go to Help-> Sys References -> System Reference Guide API like I did). This is where you learn how to delay, write to UART, write to a pin, etc. The code I made, which turns an LED on and off when numbers 1 and 2 are pressed, respectively, is below.

    #include < project.h>

    int main()
    {
        /* Place your initialization/startup code here (e.g. MyInst_Start()) */
        /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    
        // Start the SCB UART
        UART_Start();
        uint8 PinStatus; 
        uint32 input;
    
        for(;;)
        {
            input = UART_UartGetChar();     // get the input
            UART_UartPutChar(input);        // echo the input
            PinStatus = LED_pin_Read();     // check the status of the pin
        
            if (input == '1' && PinStatus == 0){
                LED_pin_Write(1);                           // turn on LED
            } else if (input == '1' && PinStatus == 1){
                UART_UartPutString("\n");
                UART_UartPutString("LED is on already, Morris");    // already on
            } else if (input == '2' && PinStatus == 1){
                LED_pin_Write(0);                           // turn off LED
            } else if (input == '2' && PinStatus == 0){
                UART_UartPutString("\n");
                UART_UartPutString("LED is off already, Morris");   // already off
            }
            CyDelay(1);
        }
    }

After that, you have to perform Bootloading. Add a Bootloadable dock from the components. Configure it, and inside, have the dependencies tab point to the bootloader hex files linked above.

The PSoC board has two programs, the bootloader (which you must first launch to update the board), and the application program, which is the actual code you write in main.c. To launch the bootloader code, you have to depress the button on the board as you are plugging it into the host (your computer).

Compile the program using Build-> Build mtm

Upload the program with tools -> Bootloader Host. You might have to plug the PSoC board in again while pressing the button on the board. Pick a serial port, edit settings, and press the blue arrow pointing down (which means UPload, but whatever).

I used TeraTerm to listen to the PSoC. The LED turned on and off with the pressing of buttons 1 and 2.