From 9feba6b8c949b5e4599ccdfc1a77444a78718af7 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 27 Mar 2025 11:08:59 +0300 Subject: [PATCH] It works now The problem was with InitCPUTimers dunction (it was commented). But some fact was found: If you flash with correct software first - Modbus is working. Then, if you comment InitCPUTimers function and flash CPU again. The Modbus still working! But, if you turn off the power Modbus will not work after power up. The reason is unknown --- DSP28335/CPU.cpp | 12 ++--- DSP28335/CPU.h | 26 +++++----- DSP28335/CPUCoreHardCodeSetup.cpp | 42 ++++++++-------- main2.cpp | 84 +++++++++++++------------------ 4 files changed, 75 insertions(+), 89 deletions(-) diff --git a/DSP28335/CPU.cpp b/DSP28335/CPU.cpp index 10dae5a..e5ec8cb 100644 --- a/DSP28335/CPU.cpp +++ b/DSP28335/CPU.cpp @@ -31,20 +31,20 @@ CPU::CPU(): void CPU::setup(DSP28335::CPUSetup& setup) { - //adc.setup(); - // + // adc.setup(); + // scib.setup(setup.scib); // // scic.setup(setup.scic); - // + InitCpuTimers(); // cpu_timers.setup(setup.timers); - // + // epwm.setup(setup.epwm); - // + // xintf.setup(setup.xintf); - // + // period_measure.set_magic((Uint32)0); // period_measure.reset(); // diff --git a/DSP28335/CPU.h b/DSP28335/CPU.h index d63a38d..49eafb3 100644 --- a/DSP28335/CPU.h +++ b/DSP28335/CPU.h @@ -46,24 +46,24 @@ struct CPUSetup DSP28335::CPUTimersSetup timers; DSP28335::EPWMSetup epwm; DSP28335::XINTFSetup xintf; - // DSP28335::ECANASetup ecana; - // DSP28335::ECANBSetup ecanb; - // DSP28335::EQEP1Setup eqep1; - // DSP28335::DiscreteOutputsSetup dout; - // Uint16 period_sync; - // Uint16 startup_period; + DSP28335::ECANASetup ecana; + DSP28335::ECANBSetup ecanb; + DSP28335::EQEP1Setup eqep1; + DSP28335::DiscreteOutputsSetup dout; + Uint16 period_sync; + Uint16 startup_period; CPUSetup(): scib(), scic(), timers(), epwm(), - xintf() - // ecana(), - // ecanb(), - // eqep1(), - // dout(), - // period_sync(0), - // startup_period(0) + xintf(), + ecana(), + ecanb(), + eqep1(), + dout(), + period_sync(0), + startup_period(0) {} };//end SYSCoreSetup diff --git a/DSP28335/CPUCoreHardCodeSetup.cpp b/DSP28335/CPUCoreHardCodeSetup.cpp index 11888ca..63f82c9 100644 --- a/DSP28335/CPUCoreHardCodeSetup.cpp +++ b/DSP28335/CPUCoreHardCodeSetup.cpp @@ -15,10 +15,10 @@ void DSP28335::CPU::get_hard_code_setup(DSP28335::CPUSetup& hsetup) // At startup number synchronization pwm's periods - // hsetup.startup_period = 20; + hsetup.startup_period = 20; - // // // synchronization every pwm's cycle - // hsetup.period_sync = 5; + // synchronization every pwm's cycle + hsetup.period_sync = 5; // @@ -33,55 +33,55 @@ void DSP28335::CPU::get_hard_code_setup(DSP28335::CPUSetup& hsetup) // // SCIC - internal interface // - // hsetup.scic.config.baudrate = SCIC_BAUDRATE_DEFAULT; - // hsetup.scic.config.parity = SCIC_PARITY_DEFAULT; - // hsetup.scic.config.stopbits = SCIC_STOPBITS_DEFAULT; - // hsetup.scic.config.lenght = SCIC_LENGHT_DEFAULT; - // hsetup.scic.gpio_setup = SCIC_GPIO_SETUP_DEFAULT; + hsetup.scic.config.baudrate = SCIC_BAUDRATE_DEFAULT; + hsetup.scic.config.parity = SCIC_PARITY_DEFAULT; + hsetup.scic.config.stopbits = SCIC_STOPBITS_DEFAULT; + hsetup.scic.config.lenght = SCIC_LENGHT_DEFAULT; + hsetup.scic.gpio_setup = SCIC_GPIO_SETUP_DEFAULT; // // CPU Timers // - // hsetup.timers.frequency = 150.0; //150MHz - // hsetup.timers.period = 1000.0; //1000us + hsetup.timers.frequency = 150.0; //150MHz + hsetup.timers.period = 1000.0; //1000us // // EPWM // - // hsetup.epwm.parameters.fpwm = 500; //Hz - // hsetup.epwm.parameters.pulse_sync = 1.0e-6; //s - // hsetup.epwm.parameters.pulse_adc_soc = 32.0e-6; //s - // hsetup.epwm.parameters.adc_soc_offset = FP_ZERO; //relative - // hsetup.epwm.parameters.adc_soc_quantity = 2; - // hsetup.epwm.gpio_setup = &DSP28335::GPIO::gpio_epwm_setup; + hsetup.epwm.parameters.fpwm = 500; //Hz + hsetup.epwm.parameters.pulse_sync = 1.0e-6; //s + hsetup.epwm.parameters.pulse_adc_soc = 32.0e-6; //s + hsetup.epwm.parameters.adc_soc_offset = FP_ZERO; //relative + hsetup.epwm.parameters.adc_soc_quantity = 2; + hsetup.epwm.gpio_setup = &DSP28335::GPIO::gpio_epwm_setup; // // XINTF // - // hsetup.xintf.gpio_setup = &DSP28335::GPIO::gpio_xintf_16bit_setup; + hsetup.xintf.gpio_setup = &DSP28335::GPIO::gpio_xintf_16bit_setup; // // ECANA // - // hsetup.ecana.gpio_setup = &DSP28335::GPIO::gpio_cana_setup; + hsetup.ecana.gpio_setup = &DSP28335::GPIO::gpio_cana_setup; // // ECANB // - // hsetup.ecanb.gpio_setup = &DSP28335::GPIO::gpio_canb_setup; + hsetup.ecanb.gpio_setup = &DSP28335::GPIO::gpio_canb_setup; // // EQEP // - // hsetup.eqep1.gpio_setup = &DSP28335::GPIO::gpio_eqep_setup; + hsetup.eqep1.gpio_setup = &DSP28335::GPIO::gpio_eqep_setup; // // Discrete Outputs // - // hsetup.dout.gpio_setup = &DSP28335::GPIO::gpio_dicrete_outputs_setup; + hsetup.dout.gpio_setup = &DSP28335::GPIO::gpio_dicrete_outputs_setup; // }//end diff --git a/main2.cpp b/main2.cpp index 93ae56f..46e5a92 100644 --- a/main2.cpp +++ b/main2.cpp @@ -28,27 +28,21 @@ interrupt void cpu_timer1_isr(void); interrupt void canb_isr(void); interrupt void canb_box_isr(void); -Periphery periphery; +// Periphery periphery; -RUDRIVEFRAMEWORK::SinglePhaseSetup power_hw_setup; -RUDRIVEFRAMEWORK::SinglePhase power_hw((uint16_t*)0x4000); - - -WEINBUS::WeinbusSlave hmi(power_hw.crc); -MODBUSRTU::ModbusRTUTransceiverConfiguration modbus_port_configuration; //---------------------------------------------------------------------------------------- -// DSP28335::SCISetup SCIbSetup; -// DSP28335::SCIB scib(ScibRegs); +DSP28335::SCISetup SCIbSetup; +DSP28335::SCIB scib(ScibRegs); -// DSP28335::MeasureTimeInterval interval_measure(CpuTimer2); +DSP28335::MeasureTimeInterval interval_measure(CpuTimer2); -// // MODBUS RTU - PORT & HMI -// MODBUSRTU::ModbusRTUTransceiverSetup modbus; -// MODBUSRTU::ModbusRTUCRC crc; -// MODBUSRTU::ModbusRTUTransceiver modbus_port(scib, interval_measure, crc); +// MODBUS RTU - PORT & HMI +MODBUSRTU::ModbusRTUTransceiverSetup modbus; +MODBUSRTU::ModbusRTUCRC crc; +MODBUSRTU::ModbusRTUTransceiver modbus_port(scib, interval_measure, crc); -// WEINBUS::WeinbusSlave hmi(crc); -// MODBUSRTU::ModbusRTUTransceiverConfiguration modbus_port_configuration; +WEINBUS::WeinbusSlave hmi(crc); +MODBUSRTU::ModbusRTUTransceiverConfiguration modbus_port_configuration; // Registers to testing HMI interface @@ -102,7 +96,7 @@ void main() PieVectTable.ECAN1INTB = &canb_box_isr; EDIS; - // InitCpuTimers(); + InitCpuTimers(); ConfigCpuTimer(&CpuTimer0, 150, 1000); // 1ms ConfigCpuTimer(&CpuTimer1, 150, 5000); // 5ms @@ -114,38 +108,34 @@ void main() PieCtrlRegs.PIEIER9.bit.INTx7 = 1; // from 5 to 8 PieCtrlRegs.PIEIER9.bit.INTx8 = 1; - periphery.config(); + // periphery.config(); //---------------------------------------------------------------------------------------- - // SCIbSetup.config.baudrate = SCIB_BAUDRATE_DEFAULT; - // SCIbSetup.config.parity = SCIB_PARITY_DEFAULT; - // SCIbSetup.config.stopbits = SCIB_STOPBITS_DEFAULT; - // SCIbSetup.config.lenght = SCIB_LENGHT_DEFAULT; - // SCIbSetup.gpio_setup = SCIB_GPIO_SETUP_DEFAULT; + SCIbSetup.config.baudrate = SCIB_BAUDRATE_DEFAULT; + SCIbSetup.config.parity = SCIB_PARITY_DEFAULT; + SCIbSetup.config.stopbits = SCIB_STOPBITS_DEFAULT; + SCIbSetup.config.lenght = SCIB_LENGHT_DEFAULT; + SCIbSetup.gpio_setup = SCIB_GPIO_SETUP_DEFAULT; - // modbus.gpio_re_de_setup = &DSP28335::GPIO::gpio_scib_re_de_setup; - // modbus.gpio_driver_enable = &DSP28335::GPIO::gpio_scib_re_de_set; - // modbus.gpio_receiver_enable = &DSP28335::GPIO::gpio_scib_re_de_clear; + modbus.gpio_re_de_setup = &DSP28335::GPIO::gpio_scib_re_de_setup; + modbus.gpio_driver_enable = &DSP28335::GPIO::gpio_scib_re_de_set; + modbus.gpio_receiver_enable = &DSP28335::GPIO::gpio_scib_re_de_clear; - // scib.setup(SCIbSetup); + scib.setup(SCIbSetup); - // interval_measure.set_magic((Uint32)0); - // interval_measure.reset(); + interval_measure.set_magic((Uint32)0); + interval_measure.reset(); - // modbus_port.setup(modbus); + modbus_port.setup(modbus); //---------------------------------------------------------------------------------------- // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM - periphery.updateVersionFPGA(); + // periphery.updateVersionFPGA(); -//---------------------------------------------------------------------------------------- - power_hw.get_hard_code_setup(power_hw_setup); - modify_hardware_setup(power_hw_setup); - power_hw.setup(power_hw_setup); - +//---------------------------------------------------------------------------------------- // MODBUS RTU // @@ -157,17 +147,13 @@ void main() // test_init_hmi_buffers(); - // modbus_port.configure(modbus_port_configuration); - power_hw.modbus_port.configure(modbus_port_configuration); + modbus_port.configure(modbus_port_configuration); clear_array((uint16_t *)hmi.rxStack, sizeof(hmi.rxStack)/sizeof(uint16_t)); clear_array((uint16_t *)hmi.txStack, sizeof(hmi.txStack)/sizeof(uint16_t)); - // modbus_port.setRXBuffer((uint16_t*)hmi.rxStack, &hmi.rxLength); - // modbus_port.setTXBuffer((uint16_t*)hmi.txStack, &hmi.txLength); - - power_hw.modbus_port.setRXBuffer((uint16_t*)hmi.rxStack, &hmi.rxLength); - power_hw.modbus_port.setTXBuffer((uint16_t*)hmi.txStack, &hmi.txLength); + modbus_port.setRXBuffer((uint16_t*)hmi.rxStack, &hmi.rxLength); + modbus_port.setTXBuffer((uint16_t*)hmi.txStack, &hmi.txLength); // interval_measure.set_magic(19); @@ -188,19 +174,19 @@ void idle_loop() { infCounter++; - periphery.initExternalModbus(); + // periphery.initExternalModbus(); // // MODBUS RTU HMI Service // - if(power_hw.modbus_port.compare_state(MODBUSRTU::BREAK)) + if(modbus_port.compare_state(MODBUSRTU::BREAK)) { - power_hw.modbus_port.port_reset(); + modbus_port.port_reset(); // } else { - power_hw.modbus_port.execute(); + modbus_port.execute(); hmi.execute(); // }//if else @@ -213,7 +199,7 @@ void idle_loop() interrupt void cpu_timer0_isr(void) { - periphery.processDigitalOutput(); + // periphery.processDigitalOutput(); PieCtrlRegs.PIEACK.all |= PIEACK_GROUP1; }//end @@ -222,7 +208,7 @@ interrupt void cpu_timer0_isr(void) interrupt void cpu_timer1_isr(){ CpuTimer1.InterruptCount++; - periphery.processDigitalInput(); + // periphery.processDigitalInput(); }